PDA

View Full Version : Running remote macro



sportphantom
02-11-2010, 09:18 AM
Hi,

My case is that I have Normal.dot and lot of other templates in the same folder. But I cannot ask "template X" to call a function written in Normal.dot Module. I read something like that:

Call ProjectName.ModuleName.FunctionName
.. but I can get it working. NormalDot project printscreen is attached.

If in normal.dot I call function directly like MyFunction(x, y) then I would like to do the same from another template.

Sub AutoNew()
... connecting to normal.dot here ...
MyFunction(x, y)
End Sub

Anyone have some ideas? :think:


Best regards,
SportPhantom
IT Engineer

lucas
02-11-2010, 09:37 AM
Don't use normal.

It's prone to corruption and holds all kinds of unnessesary info about styles, etc.

create a global template that holds all of your macro's and put it in your startup directory.

All macro's will then be available to any doc file that you have open.

lucas
02-11-2010, 09:39 AM
also, unless you are using office 97 you should use document open or document new instead of autonew.

sportphantom
02-11-2010, 12:54 PM
create a global template that holds all of your macro's and put it in your startup directory.

All macro's will then be available to any doc file that you have open.Thank you for the replay!

I am using Normal.dot as Global template. It is stored in the startup directory side with all the other useful templates (some in subfolders). All the templates are loaded to computer with GPO. All the macros and functions are stored in Global Template (normal.dot) and they are running fine there.

My aim is not to copy the same function to all standalone templates but call it with specified variables from normal.dot in case this template is used.

Btw Sub AutoNew() is working smoothly with both office03 and office07.

If I try to call the function I see:


Compile error:
Sub or Function not defined

fumei
02-11-2010, 02:20 PM
Steve (lucas) is correct. It is generally NOT a good idea to store macro procedures in Normal.dot. Even Microsoft recommends against this, as normal.dot is very prone to corruption. It is better to use a specific/explicit global template to act as a code container.

I have hundreds and hundreds of procedures available - NONE are in normal.dot.

What exactly is your code when you get the compile error?

sportphantom
02-12-2010, 12:39 AM
Private Function AddLetterhead(Office As String, Lang As String) As AutoTextEntry

This macro is adding Letterheads according to the Office Name and Language as input. Basically what it does is that it attached the content from external file (Selection.InsertFile) and does some other formating.

It is called out in Normal.dot (after I investigate the Global template issue I will try to remove it from there) like that:
Sub EstonianLetterheadPromt()
Dim L As Long
L = MsgBox(prompt:="Select YES for ESTONIAN, No for ENGLISH", _
Buttons:=vbYesNoCancel, Title:="Add Estonian Letterhead")
On Error Resume Next
If (L = 6) Then AddnLetterhead("Tallinn", "Estonian") = True
If (L = 7) Then AddLetterhead("Tallinn", "English") = True
End Sub

It is also not the best practice, I will change it to form-based approach in near future.

So my aim is now to call this function from some other template(!) when it is used to build a new document (Sub AutoNew()?) . How to do that? Case is that if I use the same code I showed in here it gives me the error. Is there some connector missing?

sportphantom
02-17-2010, 12:33 AM
Indeed, as the Reference to Normal.dot was automatically added then all I needed was:
Sub AutoNew()
On Error Resume Next
Normal.AddLetterhead("Tallinn", "English") = True
End Sub
Thanks for all your help!

BTW! How to rename threat as SOLVED? I do not see any such option..