Passing Parameters between Applications

T

Tony Broadbent

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).
 
H

Helmut Weber

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
 
T

Tony Broadbent

Helmut Weber said:
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
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top