Word 2007 setting to activate Macros in Startup Folder

C

carlo

Hi All

I use:
Windows 7
Microsoft Office 2007

I created a new Template (myRibbon.dotm) which contains a ribbon I
created with a customUI XML File.
Since I want this Ribbon to always show when I start Word I put it in
the Startup Folder for Word.
This Ribbon contains 3 buttons which act on a Macro in the normal.dotm
(works the way it is expected). Now I wanted to move the code from the
normal.dotm to the myRibbon.dotm (since I figured it's not the best
idea to blow up the normal.dotm). Now word tells me:
"The Macro was not found or has been deactivated due to your Macro
Security" (don't know the english error message, since I use the
german Office).
Which seems pretty weird to me since the Startup-Folder is listed as a
trusted source folder. Do I need to change anything else so that the
Ribbon can use the code in the myRibbon.dotm?

I'm happy for any insight

Thanks in advance and if you need any more information i would be
happy to answer your questions.

Carlo
 
G

Graham Mayor

The ribbon commands are still looking to the normal template for the macros.
You need to amend the ribbon to run the macros from their new locations,.
The ribbon will probably have an onAction command

onAction="CustRibbonBtn"

associated with each button. i.e. all the buttons will call the same macro.

In the template there will be the macro "CustRibbonBtn" that calls the
individual processes based on the ButtonIDs e.g.

<button id="Custombutton78589358"

Thus to call the macro associated that button you would have a macro in the
template similar to

Option Explicit
Sub CustRibbonBtn(control As IRibbonControl)
Select Case control.ID
Case "Custombutton1636628076", "Custombutton1231084133": PasteUnfText
Case "Custombutton990339220": AnsiValue
Case "Custombutton371625977": ClearUnpinned
Case "Custombutton279193070": CleanCue
Case "Custombutton2064822139": CopySelectedToNewDoc
Case "Custombutton849728025": CharMap
Case "Custombutton1084833382": FieldCodeToString.FieldCodeToString
Case "Custombutton1420408836": PrintPage
Case "Custombutton78589358": SuggestWord.SuggestWord
End Select
End Sub

The last entry matches the aforementioned Custombutton78589358
and runs the macro SuggestWord from the SuggestWord module.
You can associate more than one button with the same command as in the first
item

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
C

carlo

Hi Graham

Thank you very much for your response.

I still have problems with this, hope you don't mind me asking again.

I'm not calling the same Macro (or actually Sub) on the three
buttons...here's my XML:
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/
customui">
<ribbon>
<tabs>
<tab id="EZVAVF_TAB" label="EZV - AVF">
<group id="SampleGroup" label="Sample Group">
<button id="protectionOnOff" size="large"
imageMso="Lock"
label="Protection On/Off"
onAction="btnProtectAction" />
<button id="docStart" size="large"
imageMso="HappyFace"
label="Smiley????"
onAction="btnDocStartAction" />
<button id="formFieldInput" size="large"
imageMso="FormControlEditBox"
label="Input to Form Fields"
onAction="btnFormFieldsAction" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
---------------------------------------------------------------------------------------
Would it be better to use it the way you wrote? What's the actual
advantage?
(Unfortunately I couldn't find any good information sources on the
internet)

Even if I put the module "Globals." in front of the actions it doesn't
work, do I have to add the Project as well?
I tried:
- myRibbon.Globals.btnFormFieldsAction
- Globals.btnFormFieldsAction
and
- btnFormFieldsAction

none of those work.

Which actually brings me to another question:
When I open VBE I can't access the "myRibbon.dotm" it always tells me:
"Project can't be displayed" is that normal?

Thanks again for your help....i really appreciate it.

Carlo
 
G

Graham Mayor

I have tested your ribbon and it will work as you have posted it (if you
correct the header as below) with the following macros in the add-in
template (I used a module "AddInMacros" to contain the macros) -
http://www.gmayor.com/installing_macro.htm

Option Explicit

Sub btnProtectAction(control As IRibbonControl)
'do your thing here e.g.
MsgBox "btnProtectAction"
End Sub

Sub btnDocStartAction(control As IRibbonControl)
'do your thing here e.g.
MsgBox "btnDocStartAction"
End Sub

Sub btnFormFieldsAction(control As IRibbonControl)
'do your thing here e.g.
MsgBox "btnFormFieldsAction"
End Sub



<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<ribbon>
<tabs>
<tab id="EZVAVF_TAB" label="EZV - AVF">
<group id="SampleGroup" label="Sample Group">
<button id="protectionOnOff" size="large"
imageMso="Lock"
label="Protection On/Off"
onAction="btnProtectAction" />
<button id="docStart" size="large"
imageMso="HappyFace"
label="Smiley????"
onAction="btnDocStartAction" />
<button id="formFieldInput" size="large"
imageMso="FormControlEditBox"
label="Input to Form Fields"
onAction="btnFormFieldsAction" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
C

carlo

Hi Graham

Thanks again for your thorough reply.

It helped me a lot and I was able to create the myRibbon.dotm which
allows me to have my CustomUI Ribbon with buttons which call a Macro
in the same Template.

Your sentence:
"You cannot access macros in a template unless the template is open in
Word for editing."
Made me wonder 2 things though:
1st: Isn't the template open when I open in Word? At least I can find
a hidden file ~$myRibbon.dotm which usually means that word opened it.
2nd: What shall I do if I want to call functions in the myRibbon.dotm
from another document or template??
I tried to open a test-template that is based on the code in the
myRibbon.dotm. Which doesn't seem to work. BUT:
I used "TemplateNormal" as the VB-Project name for myRibbon.dotm. When
the test-template starts it wants to call a function
"TemplateNormal.StartDoc", which Word can't seem to find. If I change
the name to anything else e.g. "TempNormal" it works....this strikes
me as rather peculiar. Do you have an explanation for this? or did you
already see something similar?

Thanks again.
Carlo
 
G

Graham Mayor

1. No the template is not open for editing when it is loaded as an add-in.
it is only loaded for use, which is not the same thing.
2. Because the template is used as an add-in, its macros are always
available to other documents and templates. Though if templates require
macros, it saves a lot of confusion if you save its macros in the template.
Where you have macros in the same name in Document template, Add-in template
and Normal template, called by a toolbar/ribbon button they work in the
hierarchy

1. Document template
2. Normal template
3. Add-in template

thus if 1 is missing 2 is used, if 1 & 2 are missing, 3 is used.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
C

carlo

Thanks a bunch for explaining that.

Unfortunately my client has over 3000 templates that are based on the
code in the add-in! No chance to put the code in the templates
themself.

I see, so I should be able to use the code in the add-in from a
template like that:
-----------------------------------------
name of add-in in VBE:
TemplateNormal
-----------------------------------------
Sub in add-in:

Sub myAddInSub(i as integer)
msgbox i
end Sub

-----------------------------------------
Sub in Template:

Sub myAddInTest()
TemplateNormal.myAddInSub(5)
End Sub
-----------------------------------------

I will play some more with it and hope i will find a fix for my
problems.

Thanks again

Carlo
 
J

jm60

carlo wrote on 09/02/2010 08:25 ET
Hi Graha

Thanks again for your thorough reply

It helped me a lot and I was able to create the myRibbon.dotm whic
allows me to have my CustomUI Ribbon with buttons which call a Macr
in the same Template

Your sentence
"You cannot access macros in a template unless the template is open i
Word for editing.
Made me wonder 2 things though
1st: Isn't the template open when I open in Word? At least I can fin
a hidden file ~$myRibbon.dotm which usually means that word opened it
2nd: What shall I do if I want to call functions in the myRibbon.dot
from another document or template?
I tried to open a test-template that is based on the code in th
myRibbon.dotm. Which doesn't seem to work. BUT
I used "TemplateNormal" as the VB-Project name for myRibbon.dotm
Whe
the test-template starts it wants to call a functio
"TemplateNormal.StartDoc", which Word can't seem to find. If I chang
the name to anything else e.g. "TempNormal" it worksthis strike
me as rather peculiar. Do you have an explanation for this? or did yo
already see something similar

Thanks again
Carl
Hi

I came across this thread while trying to solve a similar problem: Calling
macro named mymacro located in a template loaded as an add-in (templat
locate
in the STARTUP folder). As you point out, simply using "CALL mymacro
fails
I found two solutions for my problem
1) Use Application.Run MacroName:="mymacro". Interestingly this work
while "CALL mymacro" fails (without the reference explained in 2)
2) In the active template (be it Normal or some other template) add a REFERENC
to the add-in project (in VBE -> Tools -> References). You can then simpl
use "CALL mymacro" (project name not required unless you have severa
macros with identical names). This works as long as the add-in template's nam
doesn't change
Your question is more complex and I don't know whether this helps.
 

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