Finding Bookmark in Header

A

Angie M.

Hello,

I have the following macro that should delete a graphic in a header that I
have marked with a bookmark:

Sub NoELtr()

Selection.HomeKey Unit:=wdStory

ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader

ActiveDocument.Bookmarks("bkltrLogo").Range.Delete

Selection.ParagraphFormat.SpaceAfter = 42

ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
Selection.MoveDown Unit:=wdLine, Count:=3

End Sub

I get an error that says it doesn't find it - could it be because it's in
the header, but I open the header. This can be done manually of course. Any
suggestions are appreciated.
 
J

Jezebel

The fact that it's in the header is irrelevant. And you don't need all that
selection and window stuff either. If the bookmark really exists (and you
haven't miss-spelled the name), then

ActiveDocument.Bookmarks("bkltrLogo").Range.Delete

is all you need. If Word is saying the bookmark doesn't exist, then it
doesn't exist (check the Insert > Bookmark dialog).
 
J

Jean-Guy Marcil

Jezebel was telling us:
Jezebel nous racontait que :
The fact that it's in the header is irrelevant. And you don't need
all that selection and window stuff either. If the bookmark really
exists (and you haven't miss-spelled the name), then

ActiveDocument.Bookmarks("bkltrLogo").Range.Delete

is all you need. If Word is saying the bookmark doesn't exist, then it
doesn't exist (check the Insert > Bookmark dialog).

Also, because the OP is doing something in the header after deleting the
logo, she would need something like:

'_______________________________________
Sub NoELtr()

Dim rgeHeader As Range

Set rgeHeader = ActiveDocument.Bookmarks("bkltrLogo").Range

With rgeHeader
.Delete
.ParagraphFormat.SpaceAfter = 42
End With

End Sub
'_______________________________________

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
A

Angie M.

HELP! this still doesn't work. I also tested it in a new blank doc with a
graphic not in the header, I selected the graphic, insert bookmark, and added
the bookmark and tried this code and also the
"ActiveDocument.Bookmarks("bkltrLogo").Range.Delete". The macro lived in a
global template but I put the macro in the actual letterhead template where
I'm trying to run the macro. I've checked the bookmark name and even deleted
and restablished it.

My real problem is that I have a graphic line in the header that I don't
want deleted otherwise it would be easy to just delete the paragraph mark
where the graphic was anchored and I wouldn't have to mess with a bookmark at
all. Any other suggestions? Thanks a lot
 
J

Jezebel

Take a deep breath and explain, from the top, what you are trying to do,
without making reference to your own (clearly unsuccessful) attempted
method.
 
A

Angie M.

I have a letterhead template that contains a logo graphic, a graphic line
below the logo and a table that contains personalized information (I have one
letterhead template for each person due to all of the personal preferences).
These items reside in the first page header. I need a macro that will delete
the logo but not the graphic line or the table, and I need a macro that will
insert the logo (this macro works fine). I have two versions of each
template, one with the logo and one without. If they start with a non-logo
template they want to be able to add a logo, if they start with the logo they
want to be able to remove it.

The big problem I'm having is that I cannot delete the logo without deleting
the line.

Yes I would have originally created one template for each person with a logo
and no logo choice on the dialog, but at this point I don't have that choice.

I've also tried to add the line to the table and jack things around but it's
a huge amount of work for the workaround when all I need to do is delete the
graphic.

Thanks for your help
 
J

Jezebel

OK, that clarifies. If the logo and line are separate graphics, the current
problem is possibly that what you've bookmarked is not the logo but the
paragraph to which it is anchored, and the line is anchored to that
paragraph also. Thus deleting the bookmark removes both graphics.

Try deleting the graphic directly, using something like --

Activedocument.Sections(1).Headers(wdHeaderFooterFirstPage).Shapes(1).Delete
 
A

Angie M.

THANK YOU JEZEBEL. I had to change it to shape 2 but IT WORKED. Thanks for
your time, I really appreciate it. I had selected the shape and added the
bookmark, I don't know why that didn't work but I don't care at this point,
just glad something worked.
 

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