bstephens
11-23-2009, 07:39 PM
I am looking to create a macro which will launch an instance of a template (.dot) file from the ribbon. The macro I created using the word's "macro recorder" is as follows:
Sub SKLetter()
'
' SKLetter Macro
'
'
Documents.Add Template:= _
"C:\Documents and Settings\Administrator\Application Data\Microsoft\Templates\SKLetter.dot" _
, NewTemplate:=False, DocumentType:=0
End Sub
The macro works OK, but the problem is that I now want to deploy it on different users machines, and the macro is hard coded to the user name "Administrator" so if I copy the macro over to a new machine where the user name is anything else other than "Administrator" (for example say the user name on the new machine is "Assistant1") the macro no longer works.
I tried using the Windows XP environment variable "%APPDATA%\Microsoft\Templates" so that the macro reads:
Sub SKLetter()
'
' SKLetter Macro
'
'
Documents.Add Template:= _
"%APPDATA%\Microsoft\Templates\SKLetter.dot" _
, NewTemplate:=False, DocumentType:=0
End Sub
but that doesn't work either.
I am not very sophisticated with VBA. Can someone point me in the right direction to write a macro that simply loads a new instance of a template (for example SKLetter.dot) when you click on a button on the ribbon and will work on computers that have different user names?
If this also helps, the following is the callback code I am using to link "Sub SKLetter" back to the ribbon.
'Callback for SKLetter onAction
Sub rxbtnSKLetter_click(control As IRibbonControl)
Call SKLetter
End Sub
Thank you in advance.
Sub SKLetter()
'
' SKLetter Macro
'
'
Documents.Add Template:= _
"C:\Documents and Settings\Administrator\Application Data\Microsoft\Templates\SKLetter.dot" _
, NewTemplate:=False, DocumentType:=0
End Sub
The macro works OK, but the problem is that I now want to deploy it on different users machines, and the macro is hard coded to the user name "Administrator" so if I copy the macro over to a new machine where the user name is anything else other than "Administrator" (for example say the user name on the new machine is "Assistant1") the macro no longer works.
I tried using the Windows XP environment variable "%APPDATA%\Microsoft\Templates" so that the macro reads:
Sub SKLetter()
'
' SKLetter Macro
'
'
Documents.Add Template:= _
"%APPDATA%\Microsoft\Templates\SKLetter.dot" _
, NewTemplate:=False, DocumentType:=0
End Sub
but that doesn't work either.
I am not very sophisticated with VBA. Can someone point me in the right direction to write a macro that simply loads a new instance of a template (for example SKLetter.dot) when you click on a button on the ribbon and will work on computers that have different user names?
If this also helps, the following is the callback code I am using to link "Sub SKLetter" back to the ribbon.
'Callback for SKLetter onAction
Sub rxbtnSKLetter_click(control As IRibbonControl)
Call SKLetter
End Sub
Thank you in advance.