String "topic" is in the bookmark name
They are insertion points; I always thought that they were insertion points and not text. Apparently I am mistaken
I add a bookmark with VBA, how do I indicate that I want it to refer to the entire text
Merci
Jo
----- Jean-Guy Marcil wrote: ----
Bonjour
Dans son message, notre ami < Joe > nous laissait savoir que
In this message, our friend < Joe > informed us that
|| Bonjour Jean-Guy
|
|| I tried the code without the GoTo's (below) and none of the bookmark
highlighted. This is wha
|| I meant when I said that it didn't work. I tried it with and without th
Collapse method
|| Neither highlighted the text at the bookmarks
|
Just to clarify something, are you looking for 1) bookmarks that have th
string "topic" in the bookmark name, or 2) bookmarks that have the strin
"topic" in the bookmark text value
If 1), are you sure that the bookamrk is a range of text and not only a
insertion point ( I mean, if you choose to display the bookmarks from Tool
Options > View, are the bookmarks represented like 1) I"Your text", or 2
["Your text"]?)
|| Any ideas
|
|| Jo
|
|| Code that I tried
|
|| Dim b As Bookmar
|
|| For Each b In ActiveDocument.Bookmark
|| If InStr(LCase(b.Name), "topic") The
|| ActiveDocument.Bookmarks(b.Name).Selec
|| With Selectio
|| .Font.Shading.BackgroundPatternColor = wdColorGree
|| .Font.Color = wdColorWhit
|| .Collaps
|| End Wit
|| End I
|| Next
|
|| ----- Jean-Guy Marcil wrote: ----
|
|| Bonjour
|
|| Dans son message, notre ami < Joe > nous laissait savoir que
|| In this message, our friend < Joe > informed us that
|
|
|| || I am using Word 2002 and have created 5 bookmarks in my documen
to b
|| used for formatting.
|| || would like to step through each bookmark and, if the nam
include
|| "Topic", I would like t
|| || highlight the text on the line where the bookmark is. Here is m
code
|| Can anyone tell me wh
|| || it doesn't work
|
|| "it doesn't work" is a bit vague! Next time, try telling us how i
does no
|| work in regards to your expectations. I am writing this because to
often 1
|| people complain that it does not work when the code is perfectly al
right
|| but they have unrealistic expectations, or 2) they may hav
realisti
|| expectations but are using the wrong code, or 3) the right code wit
|| errors... see what I mean? I do not know in which category you are
I wil
|| assume that you have appropriate expectations and are using th
right cod
|| with some errors..
|
|| I see three potential problems
|| 1
|| || For Each b In .ActiveDocument.Bookmark
|| Why the "." before ActiveDocument... is it because this is a snippe
from
|| longer bit of code and you declare an application object somewher
else? I
|| so, then never mind this comment
|| 2) If you want to highlight the bookmark, why do you select the lin
fro
|| the bookmark to the end of the line? It seems that the lin
|
|| || .EndKey Unit:=wdLine, Extend:=wdExten
|
|| is not necessary
|
|| 3
|| || .ActiveDocument.GoTo What:=wdGoToBookmark, Name:=b.Nam
|| || With .Selectio
|
|| The GoTo method when used with ActiveDocument sets a range object
but doe
|| not actively select it
|| If you insist on using GoTo, try this instead
||
|| '_______________________________________
|| Dim b As Bookmark
|| Dim myTest As Range
||
|| For Each b In ActiveDocument.Bookmarks
|| If InStr(LCase(b.Name), "topic") Then
|| Set myTest = ActiveDocument.GoTo(What:=wdGoToBookmark,
Name:=b.Name)
|| myTest.Select
|| With Selection
|| .Font.Shading.BackgroundPatternColor = wdColorGreen
|| .Font.Color = wdColorWhite
|| End With
|| End If
|| Next b
|| '_______________________________________
||
|| or
||
|| If you use GoTo with Selection, then it gets selected:
||
|| '_______________________________________
|| Dim b As Bookmark
||
|| For Each b In ActiveDocument.Bookmarks
|| If InStr(LCase(b.Name), "topic") Then
|| Selection.GoTo What:=wdGoToBookmark, Name:=b.Name
||
|| With Selection
|| .Font.Shading.BackgroundPatternColor = wdColorGreen
|| .Font.Color = wdColorWhite
|| End With
|| End If
|| Next b
|| '_______________________________________
||
|| Finally, you may want to compare with this code where the GoTo
method is not
|| necessary:
||
|| '_______________________________________
|| Dim b As Bookmark
||
|| For Each b In ActiveDocument.Bookmarks
|| If InStr(LCase(b.Name), "topic") Then
|| ActiveDocument.Bookmarks(b.Name).Select
|| With Selection
|| .Font.Shading.BackgroundPatternColor = wdColorGreen
|| .Font.Color = wdColorWhite
|| .Collapse
|| End With
|| End If
|| Next b
|| '_______________________________________
||
||
|| ||
|| || Dim b As Bookmark
|| || For Each b In .ActiveDocument.Bookmarks
|| || If InStr(LCase(b.Name), "topic") Then
|| || .ActiveDocument.GoTo What:=wdGoToBookmark,
Name:=b.Name
|| || With .Selection
|| || .EndKey Unit:=wdLine, Extend:=wdExtend
|| || .Font.Shading.BackgroundPatternColor =
wdColorGreen
|| || .Font.Color = wdColorWhite
|| || End With
|| || End If
|| || Next b
|| ||
|| || TIA,
|| ||
|| || Joe
||
|| --
|| Salut!
|| _______________________________________
|| Jean-Guy Marcil - Word MVP
|| (e-mail address removed)
|| Word MVP site:
http://www.word.mvps.org
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site:
http://www.word.mvps.org