Pass Variable From One Macro to Another

C

Colin Steadman

Suppose I have two documents - Doc1.doc and Doc2.doc. If Doc2.doc
contained this macro:

Sub Test(passedVariable)
msgbox passedVariable
End Sub

How would I go about opening Doc2.doc from Doc1.doc and passing the
Test macro a variable? I imagine this is a very simple task, but I'll
be damned if I can find an example in my book.

TIA,

Colin
 
P

Perry

Treat Doc1 as a standard class.
You can code Properties/Methods in ThisDocument
codemodule of Doc1 like below:

'Method
Sub Test(ByVal Anyval)
MsgBox Anyval
End Sub

'Property
Public Property Get TestingProp(ByVal Anyval) As String
TestingProp = Anyval & " something extra"
End Property

'From a standard module in Doc2:
Dim d as Document
set d = documents.open(Doc1.doc)

d.Test "This is being passed to Doc1
MsgBox d.TestingProp("Another test")
'(note: both will not be intellisensed but it will work)

Krgrds,
Perry
 
C

Colin Steadman

Perry said:
Treat Doc1 as a standard class.
You can code Properties/Methods in ThisDocument
codemodule of Doc1 like below:

'Method
Sub Test(ByVal Anyval)
MsgBox Anyval
End Sub

'Property
Public Property Get TestingProp(ByVal Anyval) As String
TestingProp = Anyval & " something extra"
End Property

'From a standard module in Doc2:
Dim d as Document
set d = documents.open(Doc1.doc)

d.Test "This is being passed to Doc1
MsgBox d.TestingProp("Another test")
'(note: both will not be intellisensed but it will work)

Krgrds,
Perry


Ahh yes that what I want. It all seems so obvious now you've given
the example.

Is there a name for this type of process? I have a couple VBA books
and I'd like see if I can the dirty on this process.

Thanks again.

Colin
 
P

Perry

Is there a name for this type of process?

uhh?
This wud fall under: Class programming, I guess :))

Take a robust VBA programming book, and everything
listed under Chapter Classes can be utilized for this type
of "process", taking the Document specs for granted, that is...

Note: programming a regular Class will intellisense the
properties/methds you coded in same project.
ThisDocument class will not intellisense the user defined/coded
properties, calling the class in a foreign project.

Krgrds,
Perry
 

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