PDA

View Full Version : Passing an Excel VBA variable to MS Word VBA



ChrisMac
05-25-2010, 10:53 AM
Hi,

I have a variable in excel vba and looking for passing the variable to MS word vba.

Any steer in the right direction is more than welcomed.

Thank you in advance

mdmackillop
05-29-2010, 07:43 AM
Sub TestPass()
Dim Wd, Doc
Set Wd = CreateObject("Word.application")
Set Doc = Wd.documents.Open("C:\AAA\Doc1.doc")
Wd.Visible = True
Wd.Application.Run "Test", "Data to pass"
Doc.Close
Set Doc = Nothing
Wd.Quit
Set Wd = Nothing
End Sub


In Word document

Sub Test(MyData As String)
MsgBox MyData
End Sub