I want to have a standard word document, which fills itself with data from
the database, based on an order number. I then want to call this document
from either Outlook, or Excel, passing in a parameter of the order number.
Currently I have all the code in Outlook to populate the document, but I
really want to move the code into the word template, to avoid having to
replicate the same code in both Outlook and Excel.
How, from Outlook or Excel, do I get this parameter into my Word procedure?
Currently I use something like:
Set myWord = GetObject(, "Word.Application")
Set myWordDoc = myWord.Documents.Add(strTemplatePath)
Ideally I want to just call
myWordDoc.myMacro(myOrderNo)
or something like that, but I suspect it's not so simple.
Any suggestions or guidance much appreciated.
(Apologies if this is a repeat post, I got 'page not found' when I tried to
submit).
Helmut Weber - 20 Dec 2007 16:30 GMT
Hi Tony,
from Excel:
Sub Test()
' Dim oWrd As Word.Application ! early binding
' best practice, so to speak
' but not working here and now
' maybe because of Vista, therefore
Dim oWrd As Object
Set oWrd = GetObject(, "Word.Application")
oWrd.Run "MacroTest", 4 ' a for Word unique macro-name is required!
End Sub
in Word:
Sub MacroTest(lDat As Long)
MsgBox lDat
End Sub
HTH
--
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Vista Small Business, Office XP
Tony Broadbent - 20 Dec 2007 16:44 GMT
> Hi Tony,
>
[quoted text clipped - 25 lines]
>
> Vista Small Business, Office XP
Thanks Helmut,
That is precisely what I needed.
You wouldn't believe the hours I have struggled trying to do that.
Many many thanks,
Tony