Finding bookmarks

R

Ricki Miles

I am trying to record a macro for Word XP to help in conversion of documents
from WP8. The macro in Word will find a bookmark, select its text, place
its text into a macrobutton and then delete the original bookmark and text.
Everything works well for the first bookmark (called a1), but the macro
records the bookmark name (a1) in the code so it fails to find the next
bookmark. I would like the macro to say "Find the next bookmark" without
actually naming it. Also, I would like to have this action continue until
there are no more bookmarks in the document. As I am a VBA novice, I am
grateful for any help.

Thanks,

Ricki
 
D

Doug Robbins - Word MVP

Hi Ricki,

Please paste the code into a message that you post back to the ng.

Please respond to the newsgroups for the benefit of others who may be
interested.

Hope this helps
Doug Robbins - Word MVP
 
R

Ricki Miles

Here is the code so far: (Please note that the autotext "m" becomes
{macrobutton nomacro} and the two windows that are active are the original
document and a blank document. Also, I did not choose the bookmark "a1" in
the second line fo code, it was the first one on the list in the Edit, Go
to, Bookmarks dialog). Thanks in advance.

ReplaceCodes Macro
' Macro recorded 7/14/03 by Ricki Miles
'
Selection.HomeKey Unit:=wdStory
Selection.GoTo What:=wdGoToBookmark, Name:="a1"
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Copy
Windows(1).Activate
Selection.PasteAndFormat (wdPasteDefault)
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.HomeKey Unit:=wdLine, Extend:=wdExtend
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Copy
Selection.EndKey Unit:=wdLine
Selection.TypeParagraph
ActiveWindow.View.ShowFieldCodes = Not ActiveWindow.View.ShowFieldCodes
Selection.TypeText Text:="m"
Selection.Range.InsertAutoText
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.PasteAndFormat (wdPasteDefault)
Selection.TypeBackspace
ActiveWindow.View.ShowFieldCodes = Not ActiveWindow.View.ShowFieldCodes
Selection.HomeKey Unit:=wdLine
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Copy
Selection.WholeStory
Selection.Delete Unit:=wdCharacter, Count:=1
Windows(2).Activate
Selection.PasteAndFormat (wdPasteDefault)
End Sub
 

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