Home |
Search |
Today's Posts |
#1
|
|||
|
|||
passing arguments from an excel macro to a word macro
I have an excel macro that opens a word document through a shell command.
The word document also has macros associated with it that are triggered on the "open" event. What is the best way to pass values in my excel macro to my word macro? |
#2
|
|||
|
|||
KWE,
Why do you need a shell command? Instead, open Word (and the Word Doc) from Excel VBA. That way, you can keep all your macro commands in Excel VBA and have no need to pass variables to Word. Dim appWD As Word.Application Set appWD = CreateObject("Word.Application.9") 'For Word 2K. For Word XP use "Word.Application.10" etc. appWD.Visible = False 'If you want to hide word window and have it working in the background. appWD.ChangeFileOpenDirectory "C:\directory where your word Doc is" 'Word looks here for file. appWD.Documents.Open Filename:="Your doc's name", ConfirmConversions:=False, ReadOnly:=True, _ AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", Revert:=False, _ WritePasswordDocument:="", WritePasswordTemplate:="", Format:=wdOpenFormatAuto 'Open doc You can manipulate the word doc from here using Word VBA E.g. To put today's date in a formfield bookmarked as Date appWD.ActiveDocument.FormFields("Date").Select appWD.ActiveDocument.FormFields("Date").Result = Date To close Word from Excel VBA use appWD.DisplayAlerts = wdAlertsNone 'Turn off alerts if you don't want the "Save Document?" box to show. appWD.Quit SaveChanges:=False 'Quit word Henry "KWE39" wrote in message ... I have an excel macro that opens a word document through a shell command. The word document also has macros associated with it that are triggered on the "open" event. What is the best way to pass values in my excel macro to my word macro? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Macro - Open Word with Excel macro | Excel Discussion (Misc queries) | |||
hyperlink in Excel to Word doc closes Excel doc | Excel Discussion (Misc queries) | |||
lose formatting (border) in excel cell after pasting from word | Excel Discussion (Misc queries) | |||
How to embed Word document into Excel and retain sizing, formatti. | Excel Discussion (Misc queries) | |||
Convert Word Table to Excel Spreadsheet | Excel Discussion (Misc queries) |