Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word Macro not working

Status
Not open for further replies.

Queryman

Programmer
Nov 4, 2002
243
US
I have a macro in normal.dot that I made to open a word doc and format the only table that occupies the whole page to autofit to contents first & then autofit to window, when I do this manually on the document that table gets adjusted properly, but when I try & activate the macro using a program called SAS, by just calling it, the document does not get adjusted. Here is the code form the macro.

Sub Chain_list_format()
'
' temp_list_format Macro
' Macro recorded 4/24/2003 by QUERYMAN
'
ChangeFileOpenDirectory "C:\TEMP
Documents.Open FileName:="TEMP_LIST.doc", ConfirmConversions:=False, _
ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto
Selection.WholeStory
Selection.Tables(1).AutoFitBehavior (wdAutoFitContent)
Selection.Tables(1).AutoFitBehavior (wdAutoFitContent)
Selection.Tables(1).AutoFitBehavior (wdAutoFitWindow)
Selection.Tables(1).AutoFitBehavior (wdAutoFitWindow)

End Sub



Michael

 
Hi,

Try using ActiveDocument like this...
Code:
    With ActiveDocument.Tables(1)
        .AutoFitBehavior (wdAutoFitContent)
        .AutoFitBehavior (wdAutoFitContent)
        .AutoFitBehavior (wdAutoFitWindow)
        .AutoFitBehavior (wdAutoFitWindow)
    End With
The Selection object may not have a Tables collection depending what is selected.

Hope this helps :)

Skip,
Skip@TheOfficeExperts.com
 
SAS is an application that has the ability to pull data from databases and does some processing on it. In order to present the user with a formatted report, I call some office applications like Excel or Word using DDE commands from SAS.
Thanks



Michael

 
If you are calling this from SAS,

1. I would think that you would have had to established a reference to Word
2. Have created a Word Application object

Any action on a Word document, must have a Word Application object, it would seem to me.

Skip,
Skip@TheOfficeExperts.com
 
1. I can create documents in word by starting up word using SAS and tehn doing teh processing on it using either DDE commands or opening a word macro & letting it do it's thing.

The range paste from Excel to Word seems like a great solution works great when I do it manually, I can't seem to get it to work unfortunately & can't fogure out why?
Am I missing something?




Michael

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top