Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
KWE39
 
Posts: n/a
Default 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   Report Post  
Henry
 
Posts: n/a
Default

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro - Open Word with Excel macro Bill Excel Discussion (Misc queries) 3 May 23rd 05 11:21 PM
hyperlink in Excel to Word doc closes Excel doc Hyperlinks close Excel Document Excel Discussion (Misc queries) 2 March 17th 05 02:13 AM
lose formatting (border) in excel cell after pasting from word Reverse_Solidus Excel Discussion (Misc queries) 2 March 16th 05 10:01 PM
How to embed Word document into Excel and retain sizing, formatti. Kent Excel Discussion (Misc queries) 0 February 2nd 05 07:37 PM
Convert Word Table to Excel Spreadsheet [email protected] Excel Discussion (Misc queries) 1 January 18th 05 10:57 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"