Jump to content

Macro - Microsoft Word 2007


Recommended Posts

Posted

I have recorded a macro using Microsoft Word 2007, but I don't know if it is possible to put the macro button on the ribbon toolbar. Does anyone know how to do this? I remember being able to use a right-click menu in Word XP to be able to place a macro button on the standard toolbar, but I don't seem to have that option with Word 2007.


Posted

It's possible to put macros on the mini toolbar and the Ribbon. It's easier to put in on the mini toolbar and much much harder to put it on the Ribbon.

I will put together a guide to put it on the Ribbon by end of next week...

To put it on the mini toolbar, go to Word options, customize, and search for your macro. From there, you can add it to the menu. I think you may be able to add it to the "Add-in" tab as well.

Posted
It's possible to put macros on the mini toolbar and the Ribbon. It's easier to put in on the mini toolbar and much much harder to put it on the Ribbon.

I will put together a guide to put it on the Ribbon by end of next week...

To put it on the mini toolbar, go to Word options, customize, and search for your macro. From there, you can add it to the menu. I think you may be able to add it to the "Add-in" tab as well.

Just wondering if you have had a chance to put a guide together yet for Word 2007?

Posted

Sorry I hadn't been able to put together a guide. Here's a quickie on how to do it:

In your XML code, you need the following onAction callback:

<button id="mybutton" label="mylabel" onAction="RibbonXOnAction" tag="macroname" />

Here, the onAction calls for RibbonXOnAction. The macroname is defined by tag. If your macro in VBA is called mymacro, then your tag would be tag="mymacro".

In your VBA code, you need the following so that RibbonXOnAction can find your macro:

Sub RibbonXOnAction(button As IRibbonControl)
Application.Run button.Tag
End Sub

I hope that helps.

If you get errors, like macro not found, then you need to make sure RibbonXOnAction is in the normal.dotm and the document you're working on.

Let me know if you get any problems.

Here's a link for more information:

2003 Macros in 2007

It's very advanced, but you get extract only the info you need.

Posted

damo12,

First, let me clarify from my post #2: I meant it's easy to put macros on the Quick Access Toolbar (not the mini toolbar). The QAT is the toolbar above the ribbon. Go to Word Options --> Customize. Then choose macros. You'll see all your macros there. Just Add to add them to QAT.

Second, if you are not familiar with modifying the XML markup for customizing RibbonX, you'll want to read this post: Modify Word's Ribbon.

This will give you a good foundation to modifying the RibbonX interface. Then you'll understand post #4.

I'm still working on a guide that gives you step by step directions, but it will require familiarity with Modify Word's Ribbon.

Posted (edited)
Did this help, damo12?

Yes, it did. However, I am still having problems assigning my macro to the button I have created.

Edited by damo12
Posted (edited)

Please give more detail. I don't understand at what phase you are having a problem.

Have you customized your ribbon with the button? What does your vba script look like for you macro?

Please post screenshots too.

Edited by spacesurfer
Posted
Please give more detail. I don't understand at what phase you are having a problem.

Have you customized your ribbon with the button? What does your vba script look like for you macro?

Please post screenshots too.

I managed to assign a macro to a button and got it to work (finally). Do you know how I can add additional buttons to my my group. I want to have 3 button (all the same size) and be able to resize and position them as I choose. Is this possible?

Posted

This is not difficult at all. The partial code would look like this:

<group id="mygroup" label="My Group">

<button id="button1" label="Button 1" onAction="RibbonXOnAction" tag="mymacro1"/>

<button id="button2" label="Button 2" onAction="RibbonXOnAction" tag="mymacro2"/>

<button id="button3" label="Button 3" onAction="RibbonXOnAction" tag="mymacro3"/>

</group>

This way, you can have as many buttons as you want.

The only way you can add/remove buttons freely is programatically. This requires more programming. I don't know how to do it.

Posted
This is not difficult at all. The partial code would look like this:

<group id="mygroup" label="My Group">

<button id="button1" label="Button 1" onAction="RibbonXOnAction" tag="mymacro1"/>

<button id="button2" label="Button 2" onAction="RibbonXOnAction" tag="mymacro2"/>

<button id="button3" label="Button 3" onAction="RibbonXOnAction" tag="mymacro3"/>

</group>

This way, you can have as many buttons as you want.

The only way you can add/remove buttons freely is programatically. This requires more programming. I don't know how to do it.

Thanks spacesurfer, that works well. However, I am having some difficulty recording a macro in Microsoft Word 2007. The macro I attempted to record was designed to insert a text box (simple) into a blank Word document. Here is the code that Word has generated to record this macro:

Sub Macro1()

'

' Macro1 Macro

'

'

ActiveDocument.Shapes("Text Box 2").Select

ActiveDocument.AttachedTemplate.BuildingBlockEntries(" Simple Text Box"). _

Insert Where:=Selection.Range, RichText:=True

End Sub

However, the Visual Basic editor claims that there is an error in line 1 of this code. I therefore, assume it will not execute any of the other lines of code and stops at line 1. Do you know how to debug this error, as I have spent some time trying to figure it out, without any success? Why would Word generate an error when I am using built-in functions to record this macro?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...