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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing variables in modules from word to excel

Status
Not open for further replies.

MrWiggle

Programmer
Dec 5, 2002
3
AU
I've created a module in excel to simply pass variables to a word document using Applicaton.run
This is the macro in excel
-------------------------------------------
Sub excelmacro()

Set wordapp = CreateObject("Word.Application")
wordapp.Documents.Open ("c:\test.doc")
wordapp.Visible = True
Call wordapp.Run("Project.module1.wordmacro", "my name")

End Sub
-----------------------------------------
....which is calling this macro in word

----------------------------------------------
Public Sub wordmacro(name As String)
MsgBox name
End Sub
-----------------------------------------------
This brings an error, but if i don't try to pass a variable to the macro it succeeds.
------------------------------------------
Sub excelmacro()

Set wordapp = CreateObject("Word.Application")
wordapp.Documents.Open ("c:\test.doc")
wordapp.Visible = True
Call wordapp.Run("Project.module1.wordmacro"

End Sub
-----------------------------------------------
Public Sub wordmacro()
Msgbox "this works"
End Sub

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

Can i not pass variables from one application to another?
Please help
 
try something like this

' excel macro

Option Explicit

Sub excelmacro()
Dim wordapp As Object
Dim doc As Object

Set wordapp = CreateObject("Word.Application")
Set doc = wordapp.Documents.Open("c:\test.doc")

doc.Variables.Add "user", "Justin"
doc.Saved = True ' to get rid of save dialog
wordapp.Visible = True

Call wordapp.Run("Project.module1.wordmacro")

End Sub


' word macro

Option Explicit

Public Sub wordmacro()
MsgBox "Hello " & ThisDocument.Variables("user")
End Sub
 
MrWiggle,

I played around with your code awhile and got it to work (with passing the procedure argument) if I removed the macroname qualifiers. Example:

Code:
Call wordapp.Run("wordmacro", "my name")

You might want to try this.


Regards,
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top