![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Feb 2002
Posts: 4
|
Hi.
I am using Excel 2000 to Control Word 2000 for publication generation. I will need to pass certain variable from Excel VBA to Word VBA (I use Word VBA's Autoexec module to run the script once Excel opens the Word document). Does anyone know how to do it? thanks, John |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 2,908
|
One way you could do it is this:-
In Word use something like this in a standard module:- Code:
Sub WordMacro(VariableFromXL As String) MsgBox VariableFromXL End Sub Code:
Sub OpenWordAndPassVariable()
Dim wdApp As Word.Application
YourVariable = "Hello there world!"
Set wdApp = CreateObject("Word.Application")
wdApp.Documents.Open "C:tempwordfile.doc"
wdApp.Visible = True
wdApp.Run "WordMacro", YourVariable
End Sub
Also, the code above assumes you've set a reference to the Word object library in Tools, References. HTH, D |
|
|
|
|
|
#3 |
|
New Member
Join Date: Feb 2002
Posts: 4
|
Thanks for your reply!
Are these codes for Excel 2000 or Excel 97. I have Excel 97 and also click "Microsoft Word 8.0 Libary" but when I run the code I get an error message "Compile error: wrong number of arguments or invalid property assignment" at the line: wdApp.Run "WordMacro", YourVariable (.Run is highlighted). Could you tell me why? Thanks, John |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|