Solved

Macros / Custom Toolbar Help - Word 2007/2010

Posted on 2010-09-21
5
1,332 Views
Last Modified: 2012-05-10
I have a DOT file that I need to modify  - it was created in Word 2003.  There are 10+ macros assigned to the custom toolbar.  

I need to know how, in Word 2010 (or 2007, which I also have) I can do the following:
a) find out which macro is assigned to a specific icon on the toolbar; and
b) create / copy it to a different template (which also has to be in "DOT" (not DOTM/DOTX) format.

I've looked at a ton of reference materials but am not finding this.  

The DOT needs to work in 2003.
0
Comment
Question by:aaepa
  • 2
  • 2
5 Comments
 
LVL 8

Assisted Solution

by:PandaPants
PandaPants earned 250 total points
ID: 33729457
I have neither Word 2010 nor 2007, but I can give you something that will likely work, if you want to take the time:
Since you have access to the template, open it up to where you can see the code, then put a break point at the beginning of each macro or function. Return to the Word window and run the first macro on the toolbar; the code should stop immediately at one of the break points you assigned. Make a note, and move on to the next one.

If there are many more macros in the template than on the toolbar, there will be a lot of prep involved, but it will work eventually. (Unless, of course, some of the toolbar icons refer to macros in other templates that are assumed to be available...but we don't have to go there right away.) Good luck.
0
 
LVL 8

Expert Comment

by:PandaPants
ID: 33729502
Sorry, I forgot to address your second question, regarding sharing. For that, use the 2010 equivalent (I'm assuming there is one) of the Organizer tool to copy the code modules from one template to another.

If you want to copy *only* the 10 or so macros that are directly called from the toolbar, and they're not already all in the same module, you can either (a) create a new module and copy those macros to that new module with the copy-and-paste method, or (b) copy all the modules to the new template and then delete those macros that you don't need.

A word of caution, probably not needed: It's possible--even likely--that the macro called by the toolbar icon actually chains to other macros that aren't directly referenced from the toolbar, and those macros may link to others still. So, even if you identify the 10 macros on the toolbar, you may actually need to copy more than those in order to retain functionality.

Again, it's a timeconsuming process if the web is tangled, but it is possible to follow each and every thread. Have patience...and hope another expert comes along with a better solution!
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 250 total points
ID: 33733400
This code will list all the buttons which run macros. It was designed in Word 2003
Sub ListButtons()

    Dim bar As CommandBar

    Dim but As CommandBarControl

    Dim tbl As Table

    Dim rw As Row

    Dim rng As Range

    

    

    Set tbl = ActiveDocument.Tables.Add(ActiveDocument.Bookmarks("\EndOfDoc").Range, 1, 4)

    tbl.Cell(1, 1).Range.Text = "Toolbar"

    tbl.Cell(1, 2).Range.Text = "Button"

    tbl.Cell(1, 3).Range.Text = "On Action"

    tbl.Cell(1, 4).Range.Text = "Icon"

    

    For Each bar In CommandBars

        For Each but In bar.Controls

            If but.Type = msoControlButton Then

                If Len(but.OnAction) > 0 Then

                    Set rw = tbl.Rows.Add

                    

                    rw.Cells(1).Range.Text = bar.Name

                    rw.Cells(2).Range.Text = but.Caption

                    rw.Cells(3).Range.Text = but.OnAction

                    

                    but.CopyFace

                    Set rng = rw.Cells(4).Range

                    rng.Collapse wdCollapseStart

                    rng.Paste

                End If

            End If

        Next but

    Next bar

End Sub

Open in new window

0
 

Author Closing Comment

by:aaepa
ID: 33736795
Thank you... I have it working now - I found the missing macro :).  FYI - there is no way in 2007 or 2010 to edit a custom toolbar that appears in "Add-Ins" (at least that is what I have read in numerous places today!)  It can be added to the quick access toolbar, but not to an "add-in".  
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 33738182
Hi thanks. I'm glad that you're sorted.

The macro should list add-ins with a button starter in Word 2007. It did in my tests.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
Outlook Free & Paid Tools
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now