A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Automating Word from script



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old August 18th 09, 05:43 PM posted to microsoft.public.outlook.program_vba
Joel Allen
external usenet poster
 
Posts: 117
Default Automating Word from script

Outlook 2003 SP3

Hi,

I currently automate a Word document via my script from my custom outlook
task. I use bookmarks and it works great.

However, now I have a need now to insert tables, change font size, etc.....
I'm having trouble with the basics like trying to insert text into a certain
cell then tabbing to the next cell. I tried vbTab but no luck.

Does anybody have a good reference to learn from? I'm looking for sample
code and maybe sample Word files and perhaps a list of vb commmands. I'm
only aware of a few like vbTab and vbCrLf.

Thank you very much,
Joel


Ads
  #2  
Old August 18th 09, 07:54 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Automating Word from script

A good Word programming book might help. The Word MVPs have a Web site that
has a lot of information and code samples at http://word.mvps.org/ that
might also be helpful to you.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Joel Allen" wrote in message
...
Outlook 2003 SP3

Hi,

I currently automate a Word document via my script from my custom outlook
task. I use bookmarks and it works great.

However, now I have a need now to insert tables, change font size,
etc..... I'm having trouble with the basics like trying to insert text
into a certain cell then tabbing to the next cell. I tried vbTab but no
luck.

Does anybody have a good reference to learn from? I'm looking for sample
code and maybe sample Word files and perhaps a list of vb commmands. I'm
only aware of a few like vbTab and vbCrLf.

Thank you very much,
Joel


  #3  
Old August 18th 09, 07:57 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP][_3_]
external usenet poster
 
Posts: 465
Default Automating Word from script

The easiest way to get sample code is to turn on Word's macro recorder as
you perform the tasks you want to accomplish. Then, look at the macro, see
what objects are are involved, check out their methods, etc.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Joel Allen" wrote in message
...
Outlook 2003 SP3

Hi,

I currently automate a Word document via my script from my custom outlook
task. I use bookmarks and it works great.

However, now I have a need now to insert tables, change font size,
etc..... I'm having trouble with the basics like trying to insert text
into a certain cell then tabbing to the next cell. I tried vbTab but no
luck.

Does anybody have a good reference to learn from? I'm looking for sample
code and maybe sample Word files and perhaps a list of vb commmands. I'm
only aware of a few like vbTab and vbCrLf.

Thank you very much,
Joel



  #4  
Old August 18th 09, 08:50 PM posted to microsoft.public.outlook.program_vba
Joel Allen
external usenet poster
 
Posts: 117
Default Automating Word from script

Thank you Sue. I think this will help a lot.

Now, I started simple with this:

Selection.Font.Name = "Calibri"
and
objDoc.Selection.Font.Size = 11

Neither work. I think I need to set some variables or something. Do you
have some sample code of that? I think if I can get that far, I can take it
on my own.

Again, thanks always for your help,
Joel



"Sue Mosher [MVP]" wrote in message
...
The easiest way to get sample code is to turn on Word's macro recorder as
you perform the tasks you want to accomplish. Then, look at the macro, see
what objects are are involved, check out their methods, etc.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Joel Allen" wrote in message
...
Outlook 2003 SP3

Hi,

I currently automate a Word document via my script from my custom outlook
task. I use bookmarks and it works great.

However, now I have a need now to insert tables, change font size,
etc..... I'm having trouble with the basics like trying to insert text
into a certain cell then tabbing to the next cell. I tried vbTab but no
luck.

Does anybody have a good reference to learn from? I'm looking for sample
code and maybe sample Word files and perhaps a list of vb commmands. I'm
only aware of a few like vbTab and vbCrLf.

Thank you very much,
Joel





  #5  
Old August 18th 09, 09:49 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP][_3_]
external usenet poster
 
Posts: 465
Default Automating Word from script

Outlook doesn't know anything about any Selection object that comes from a
Word document, so you have to add the "missing links" that indicate where
that Selection is coming from. See
http://turtleflock-ol2007.spaces.liv...E3D8!579.entry
for an example.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Joel Allen" wrote in message
...
Thank you Sue. I think this will help a lot.

Now, I started simple with this:

Selection.Font.Name = "Calibri"
and
objDoc.Selection.Font.Size = 11

Neither work. I think I need to set some variables or something. Do you
have some sample code of that? I think if I can get that far, I can take
it on my own.

Again, thanks always for your help,
Joel



"Sue Mosher [MVP]" wrote in message
...
The easiest way to get sample code is to turn on Word's macro recorder as
you perform the tasks you want to accomplish. Then, look at the macro,
see what objects are are involved, check out their methods, etc.



"Joel Allen" wrote in message
...
Outlook 2003 SP3

Hi,

I currently automate a Word document via my script from my custom
outlook task. I use bookmarks and it works great.

However, now I have a need now to insert tables, change font size,
etc..... I'm having trouble with the basics like trying to insert text
into a certain cell then tabbing to the next cell. I tried vbTab but no
luck.

Does anybody have a good reference to learn from? I'm looking for
sample code and maybe sample Word files and perhaps a list of vb
commmands. I'm only aware of a few like vbTab and vbCrLf.

Thank you very much,
Joel







  #6  
Old August 19th 09, 12:12 AM posted to microsoft.public.outlook.program_vba
Joel Allen
external usenet poster
 
Posts: 117
Default Automating Word from script

I made some progress using your blog and the macro recorder in Word. I got
selection to work with a few minor tweaks.

Now I'm trying to insert tables and format them and having really hard
time. I have to guess at the formatting. For instance, this is what the
Word macro shows:

--------------------
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:= _
5, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
With Selection.Tables(1)
If .Style "Table Grid" Then
.Style = "Table Grid"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
End With
------------------------

then I'm just trying to start simple by adding just one row of a table by
doing this in my task code:

---------------
objTable.Add Range:=objSel.Range, NumRows:=1, NumColumns:= 5

or

objTable.Add Range:=objSel.Range, NumRows:=1, NumColumns:= 5

objTable.Rows.Add()
objSel.Range, NumRows=1, NumColumns=5

or


---------------


"Sue Mosher [MVP]" wrote in message
...
Outlook doesn't know anything about any Selection object that comes from a
Word document, so you have to add the "missing links" that indicate where
that Selection is coming from. See
http://turtleflock-ol2007.spaces.liv...E3D8!579.entry
for an example.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Joel Allen" wrote in message
...
Thank you Sue. I think this will help a lot.

Now, I started simple with this:

Selection.Font.Name = "Calibri"
and
objDoc.Selection.Font.Size = 11

Neither work. I think I need to set some variables or something. Do you
have some sample code of that? I think if I can get that far, I can take
it on my own.

Again, thanks always for your help,
Joel



"Sue Mosher [MVP]" wrote in message
...
The easiest way to get sample code is to turn on Word's macro recorder
as you perform the tasks you want to accomplish. Then, look at the
macro, see what objects are are involved, check out their methods, etc.



"Joel Allen" wrote in message
...
Outlook 2003 SP3

Hi,

I currently automate a Word document via my script from my custom
outlook task. I use bookmarks and it works great.

However, now I have a need now to insert tables, change font size,
etc..... I'm having trouble with the basics like trying to insert text
into a certain cell then tabbing to the next cell. I tried vbTab but
no luck.

Does anybody have a good reference to learn from? I'm looking for
sample code and maybe sample Word files and perhaps a list of vb
commmands. I'm only aware of a few like vbTab and vbCrLf.

Thank you very much,
Joel









  #7  
Old August 19th 09, 12:16 AM posted to microsoft.public.outlook.program_vba
Joel Allen
external usenet poster
 
Posts: 117
Default Automating Word from script

I made some progress using your blog and the macro recorder in Word. I got
selection to work with a few minor tweaks. Works great.

Now, I'm trying to insert tables and format them and am having a really hard
time. I have to guess at the formatting. For instance, this is what the
Word macro shows:

--------------------
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:= _
5, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
With Selection.Tables(1)
If .Style "Table Grid" Then
.Style = "Table Grid"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
End With
------------------------

Then I'm just trying to start simple by adding just one row of a table by
doing this in my task code:

---------------
objTable.Add Range:=objSel.Range, NumRows:=1, NumColumns:= 5

or

objTable.Add Range=objSel.Range, NumRows=1, NumColumns= 5

or

objTable.Add Range
objSel.Range, NumRows=1, NumColumns= 5
---------------

None of these work. It's hard to figure the conversion. Is there somewhere
where I can look at the proper format?

Thank you Sue,
Joel

"Sue Mosher [MVP]" wrote in message
...
Outlook doesn't know anything about any Selection object that comes from a
Word document, so you have to add the "missing links" that indicate where
that Selection is coming from. See
http://turtleflock-ol2007.spaces.liv...E3D8!579.entry
for an example.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Joel Allen" wrote in message
...
Thank you Sue. I think this will help a lot.

Now, I started simple with this:

Selection.Font.Name = "Calibri"
and
objDoc.Selection.Font.Size = 11

Neither work. I think I need to set some variables or something. Do you
have some sample code of that? I think if I can get that far, I can take
it on my own.

Again, thanks always for your help,
Joel



"Sue Mosher [MVP]" wrote in message
...
The easiest way to get sample code is to turn on Word's macro recorder
as you perform the tasks you want to accomplish. Then, look at the
macro, see what objects are are involved, check out their methods, etc.



"Joel Allen" wrote in message
...
Outlook 2003 SP3

Hi,

I currently automate a Word document via my script from my custom
outlook task. I use bookmarks and it works great.

However, now I have a need now to insert tables, change font size,
etc..... I'm having trouble with the basics like trying to insert text
into a certain cell then tabbing to the next cell. I tried vbTab but
no luck.

Does anybody have a good reference to learn from? I'm looking for
sample code and maybe sample Word files and perhaps a list of vb
commmands. I'm only aware of a few like vbTab and vbCrLf.

Thank you very much,
Joel









  #8  
Old August 19th 09, 01:03 AM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP][_3_]
external usenet poster
 
Posts: 465
Default Automating Word from script

Outlook doesn't recognize ActiveDocument. So, you need a Word.Document
object; the article I suggested earlier shows how to get that from a
message.

For the sake of discussion, let's say you have a Word.Document object
variable named objDoc. As your recorded macro suggests, any Document has a
Tables collection. As with other Office objects that have an Add method,
adding a table returns the newly created Table object, e.g.:

Set newTable = objDoc.Tables.Add 'etc., using parameters like those in
your code below

Once you have the newTable object, then you can manipulate it using the
Style, ApplyStyleHeadingRows, and other properties that the macro recorder
helped you find.

Remember to use the object browser (F2 in VBA) to look up any properties and
methods you don't understand and read about them in Help, where you'll
probably find more complete examples to supplement what the macro recorder
gives you. For example, since you want to add a row to the table, the object
browser can show you that the Table object has a Rows property, which in
turn has an Add method. So you can add a new row simply with:

Set newRow = newTable.Rows.Add

Inserting text in a cell in that row looks like this:

newRow.Cells(1).Range.InsertAfter "some text"
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Joel Allen" wrote in message
...
I made some progress using your blog and the macro recorder in Word. I got
selection to work with a few minor tweaks. Works great.

Now, I'm trying to insert tables and format them and am having a really
hard
time. I have to guess at the formatting. For instance, this is what the
Word macro shows:

--------------------
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:=
_
5, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
With Selection.Tables(1)
If .Style "Table Grid" Then
.Style = "Table Grid"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
End With
------------------------

Then I'm just trying to start simple by adding just one row of a table by
doing this in my task code:

---------------
objTable.Add Range:=objSel.Range, NumRows:=1, NumColumns:= 5

or

objTable.Add Range=objSel.Range, NumRows=1, NumColumns= 5

or

objTable.Add Range
objSel.Range, NumRows=1, NumColumns= 5
---------------

None of these work. It's hard to figure the conversion. Is there
somewhere where I can look at the proper format?

Thank you Sue,
Joel

"Sue Mosher [MVP]" wrote in message
...
Outlook doesn't know anything about any Selection object that comes from
a Word document, so you have to add the "missing links" that indicate
where that Selection is coming from. See
http://turtleflock-ol2007.spaces.liv...E3D8!579.entry
for an example.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Joel Allen" wrote in message
...
Thank you Sue. I think this will help a lot.

Now, I started simple with this:

Selection.Font.Name = "Calibri"
and
objDoc.Selection.Font.Size = 11

Neither work. I think I need to set some variables or something. Do
you have some sample code of that? I think if I can get that far, I can
take it on my own.

Again, thanks always for your help,
Joel



"Sue Mosher [MVP]" wrote in message
...
The easiest way to get sample code is to turn on Word's macro recorder
as you perform the tasks you want to accomplish. Then, look at the
macro, see what objects are are involved, check out their methods, etc.



"Joel Allen" wrote in message
...
Outlook 2003 SP3

Hi,

I currently automate a Word document via my script from my custom
outlook task. I use bookmarks and it works great.

However, now I have a need now to insert tables, change font size,
etc..... I'm having trouble with the basics like trying to insert text
into a certain cell then tabbing to the next cell. I tried vbTab but
no luck.

Does anybody have a good reference to learn from? I'm looking for
sample code and maybe sample Word files and perhaps a list of vb
commmands. I'm only aware of a few like vbTab and vbCrLf.



 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Script help - retain forwarded email body & location of script Dawn[_2_] Outlook and VBA 5 July 16th 09 06:35 PM
Outlk 2k3 Script: Saving Excel File programticaly from OUTLOOK SCRIPT news.microsoft.com Outlook and VBA 3 November 22nd 06 04:33 PM
automating attachments Joel Outlook and VBA 0 November 12th 06 03:47 PM
Run A SCRIPT - Select Script EMPTY mitupan116 Outlook and VBA 1 November 2nd 06 10:36 PM
Rule 'run a script' not running my script [email protected] Outlook and VBA 3 May 30th 06 01:09 PM


All times are GMT +1. The time now is 08:49 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.