Adding Macros to Toolbar


J

jokelly27

I have managed to create a footer for the insertion of filename and path
in Word 2007 documents. This appears in the Footer Gallery and works
well on any saved document if I go to Insert, Footer and then scroll
down to select my footer. This is a bit tedious so I have been trying
to record a macro for this and put it on the Quick Access Toolbar. The
macro records without problem and I assign it to a button on the qat as
instructed. However, when I try to run it on any document I get a
runtime error 5941 notifying 'the requested member of the collection
does not exist'. I am stumped over this and wonder if anyone else has
tried this. I have other macros which I used to use with Word 2000 and
will recreate these, but I do need a one button access for them, not a
hunt through menus.
 
Ad

Advertisements

G

Graham Mayor

It is not the adding of the macro to the QAT that's the problem but that the
macro recorder makes a dog's breakfast of recording matters relating to
building blocks. However, there can be any number of footers in a document.
The following macro will insert the filename and path in all the footers of
a document after any existing footer.

Sub InsertPathInFooters()
Dim iSec As Integer
Dim oFooter As HeaderFooter
Dim oSection As Section
Dim rFooter As Range
With ActiveDocument
If Len(.Path) = 0 Then .Save
For Each oSection In ActiveDocument.Sections
For Each oFooter In oSection.Footers
Set rFooter = oFooter.Range
rFooter.InsertAfter vbCr & .FullName
With rFooter.Paragraphs(rFooter.Paragraphs.Count)
.Alignment = wdAlignParagraphRight
With .Range
.Font.name = "Arial"
.Font.Size = 8
End With
End With
Next oFooter
Next oSection
End With
End Sub


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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
A

Amish

Another option is to add the path and filename to your template, so it
will be there automatically.
 
J

jokelly27

Graham said:
It is not the adding of the macro to the QAT that's the problem but that
the
macro recorder makes a dog's breakfast of recording matters relating to

building blocks. However, there can be any number of footers in a
document.
The following macro will insert the filename and path in all the
footers of
a document after any existing footer.

Sub InsertPathInFooters()
Dim iSec As Integer
Dim oFooter As HeaderFooter
Dim oSection As Section
Dim rFooter As Range
With ActiveDocument
If Len(.Path) = 0 Then .Save
For Each oSection In ActiveDocument.Sections
For Each oFooter In oSection.Footers
Set rFooter = oFooter.Range
rFooter.InsertAfter vbCr & .FullName
With rFooter.Paragraphs(rFooter.Paragraphs.Count)
.Alignment = wdAlignParagraphRight
With .Range
.Font.name = "Arial"
.Font.Size = 8
End With
End With
Next oFooter
Next oSection
End With
End Sub


--

Graham Mayor - Word MVP


Thank you for the macro. I have to confess I don't know what to do
with your blueprint above. How can I copy this or do I have to go
through the commands? I have seen other macros written like this on
forums, but it is time I learned what you do with them. I am about
intermediate but haven't done much beyond uncomplicated addition of a
few macro buttons in Word 2000 - how can this version 2007 be an
improvement? I am finding it non-intuitive and have downloaded the
interactive old 2000 version which does help somewhat.
 
Ad

Advertisements

Ad

Advertisements


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