Greg
Wed Aug 13 15:27:37 PDT 2008
Gents,
I really don't know enough about the mechanics of VBA to explain it, but I
think I have been able to achieve what James is trying to do.
I created a .dot template that loads at startup. It contains a module named
Test_Procedures and the following code:
Private Sub Test1()
MsgBox "Call Test1 tested sat sat."
End Sub
Sub Test2(ByRef pStr As String)
MsgBox pStr & " test tested sat."
End Sub
Function Test3(ByRef pStr As String) As String
Test3 = "This test on passing variable to a " & pStr & " tested sat."
End Function
I then open a new document and paste in the following code.
Sub Testing()
On Error GoTo Err_Handler
'This works
Application.Run "Test1"
'While this doesn't
Application.Run MacroName:="TestTemplate.Test_Procedures.Test1"
'This works
Application.Run "Test2", "Passing variable"
'While this doesn't
Application.Run MacroName:="TestTemplate.Test_Procedures.Test2",
varg1:="Passing variable"
'This works
MsgBox Application.Run("Test3", "Function")
'While this doesn't
MsgBox Application.Run(MacroName:="TestTemplate.Test_Procedures.Test3",
varg1:="Function")
Exit Sub
Err_Handler:
MsgBox Err.Description
Resume Next
End Sub
You can see the results for yourself. I don't know why the procedures fail
to run it you call the macro by template, module, and name as the help file
indicates.
james_davey1@yahoo.co.uk wrote:
> I've been stuck for far too long on this - please can someone help
> me ?!
>
> Ok, here's what I'm doing. I have a word template (.dot) with loads of
> code in it. It's in startup.
>
> I am opening a new document, inserting a code module, and I want to
> call a function in the template (which is loaded)
>
> Apparently this seems impossible?
>
> For example, if I create a routine in my template:
>
> Public sub Check()
>
> ..whatever...
>
> End sub
>
> I can run it from my other code module using
> application.run("templatename.modulename.Check")
>
> However if I change sub to function - one big error.
>
> I also cannot pass anything in to this routine when it's a sub. For
> example:
>
> application.run("templatename.modulename.Check", arg1) will not get to
> Public Sub Check (arg1 as var) in the template.
>
> Surely this is possible? Exactly the same thing works fine in Excel
> VBA... what am I missing???
>
>
> Any help would be much appreciated
--
Greg Maxey - Word MVP
My web site
http://gregmaxey.mvps.org
Word MVP web site
http://word.mvps.org