Macro for bookmarks in footer

O

Oz Springs

I have two bookmarks in the footer of a template. To access them I need to
open the footer first.

I have tried recording this and then to amend the macro later, but the
created macro is an if header/footer etc. and I cannot get the macro to
work.

I am wondering if someone could help with a macro which will open the footer
if it isn¹t open already (not mentioning header at all) and select one
bookmark. This macro will go in a button in a toolbar, and a button for the
other bookmark.

Thanks for any help




Oz
 
M

matt neuburg

Oz Springs said:
I have two bookmarks in the footer of a template. To access them I need to
open the footer first.

I have tried recording this and then to amend the macro later, but the
created macro is an if header/footer etc. and I cannot get the macro to
work.

I am wondering if someone could help with a macro which will open the footer
if it isn't open already (not mentioning header at all) and select one
bookmark. This macro will go in a button in a toolbar, and a button for the
other bookmark.

tell application "Microsoft Word"
tell active document
tell section 1
select bookmark 1 of text object of (get footer it index header
footer primary)
end tell
end tell
end tell

m.
 
J

JE McGimpsey

Oz Springs said:
I have two bookmarks in the footer of a template. To access them I need to
open the footer first.

I have tried recording this and then to amend the macro later, but the
created macro is an if header/footer etc. and I cannot get the macro to
work.

I am wondering if someone could help with a macro which will open the footer
if it isn¹t open already (not mentioning header at all) and select one
bookmark. This macro will go in a button in a toolbar, and a button for the
other bookmark.

One way:

Assuming you have only one section and no First Page footer:

Public Sub SelectFooterBookmarkNumberOne()
ActiveDocument.Sections(1).Footers( _
wdHeaderFooterPrimary).Range.Bookmarks(1).Select
End Sub

Public Sub SelectFooterBookmarkNumberTwo()
ActiveDocument.Sections(1).Footers( _
wdHeaderFooterPrimary).Range.Bookmarks(2).Select
End Sub
 
O

Oz Springs

Thank you very much. The bookmark macro works very well.

One more request: How can I tell the footer to close and to open back in
page layout view? These don¹t work:

ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument - for closing
ActiveWindow.ActivePane.View.Type = wdPageView - for setting the view

- but maybe I have got them out of context.

Thanks for any help




Oz
 
O

Oz Springs

Hi Matt

Thanks for this, but unfortunately the macro is going to be used on a PC so
I need it in VB...

Kind regards



Oz
 
J

John McGhie

If you stick with what you recorded, remembering to record the "Close" when
you have finished, the code will work fine on both PC and Mac.

The trick is to record starting from Normal View. This records another
layer of IF statements that will ensure that Word has the correct View
options set before it opens the window.

You need to understand that the HeadersFooters collection is not "in" the
document. It is one of the multiple "Stories" of text in a Word document
that are not in the Main Text Story.

For headers and footers, things get very complex, because the one you want
may or may not be in the section break following the place in the document
where the header or footer appears. If it's not, the following header or
footer contains simply a pointer to the section break that does contain the
requested header or footer.

Consequently, you actually have to write proper code to ensure that the
header or footer that you want has been returned. Then "Selecting" it
becomes a different problem. Since the header or footer is not in the
document text, you need to open a new window into the file to see it.

The exact command you use to do this depends on what view you are currently
in, which is why Word does all this fluffing around with the SeekView
method.

If all you want to do is manipulate the content of a bookmark, there are
easier ways to do this. Maybe you want to tell us what you are actually
trying to do next? I would have thought that placing a Field in the header
or footer would make things easier. You can manipulate its contents
directly without having to open the header or footer.

Cheers

Hi Matt

Thanks for this, but unfortunately the macro is going to be used on a PC so
I need it in VB...

Kind regards



Oz

--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Consultant Technical Writer
Sydney, Australia +61 4 1209 1410
 

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