PDA

View Full Version : Find and Replace Bookmarked Image in Footer



clhare
11-19-2010, 07:27 AM
I need to switch a logo in the first page footer to another logo. I have bookmarked the logo and created an AutoText entry for the replacement logo. I created a simple macro for this by recording my steps (all I added was the comments). When I recorded this macro, it worked great. When I run it, it says it can't find the bookmark.

How do I get this macro to work? I can't just replace the entire footer as it also contains 2 lines of text that needs to stay.
Sub SwitchToBlackLogoInFooter()

' Go to start of document to get to title page
Selection.HomeKey Unit:=wdStory
' Go to footer
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
If Selection.HeaderFooter.IsHeader = True Then
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Else
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
End If
' Go to logo bookmark
Selection.GoTo What:=wdGoToBookmark, Name:="FooterLogo"
With ActiveDocument.Bookmarks
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
' Delete logo
Selection.ShapeRange.Delete
' Insert AutoText entry for new logo
NormalTemplate.AutoTextEntries("FooterLogo_Black").Insert Where:=Selection _
.Range, RichText:=True
' Return to main document
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub

fumei
11-19-2010, 09:57 AM
1. You deleted the bookmark.

2. why are you using View? You have seen enough header threads to know you do not ned to do this.

clhare
11-19-2010, 01:08 PM
I know, but I have SUCH a hard time with header and footer macros and with ranges. I was trying for "simple" since it only needed to go work in one location.

fumei
11-19-2010, 01:38 PM
OK.

If the logo is the ONLY thing in the footer, then it is very easy. Simply put in the graphic via Autotext, using the range.

Sub FooterLogo()
NormalTemplate.AutoTextEntries("FooterLogo_Black").Insert _
Where:=ActiveDocument.Sections(1).Footers(2).Range, _
RichText:=True
End Sub


There is no need to go to the start of the document; no need to go into View, no need for a bookmark, etc. etc. etc.


If the footer has content that you want to retain, that is another issue. You do not say one way or the other.

clhare
11-23-2010, 06:29 AM
The footer does have text in it. I need to replace the graphic with a new graphic (which I have saved as an AutoText so it will position correction when inserted).

The graphic I need to replace without messing up the text is in the title page footer only.

Is it possible to find it and replace it if it is not bookmarked? Or would it have to be bookmarked in order to do it?

clhare
11-23-2010, 06:36 AM
Sorry--meant to create a new post!