Change Bookmark Range Font

G

George Seese

The document has this:
Italic text. Placeholder Bookmark
--------------
With this code,
Sub ChangeFontInBookmarkRange()
ActiveDocument.Bookmarks(1).Range.Font.Italic = False
ActiveDocument.Bookmarks(1).Range.Text = "This should not be italics"
End Sub
 
M

mksmith

George

I would change your code a little because what it is doing is to change
the font of the FIRST bookmark in the document.

What would you do if you wanted to change, say, the second or third
bookmark? Or what if there was no document open or that the active
document has no bookmarks?

How about:

Sub ChangeFontInBookmarkRange(nBookmark as Long)

If Documents.Count > 0 then
If ActivedOcument.Bookmarks.Count >= nBookmark then
If nBookmark > 0 then
ActiveDocument.Bookmarks(nBookmark).Range.Font.Italic = False
ActiveDocument.Bookmarks(nBookmark).Range.Text = "This should
not be italics"
end if
end if
endif

End Sub


Note that I haven't tested this routine but it ought to fly. If you have
any questions then please do get back to me.

Malc
www.dragondrop.com
 
G

George Seese

I'm working with a test document that has only:
Italic text, followed by a Placeholder Bookmark.
There is one bookmark. I added this code to verify there is only one
bookmark:
nCount = ActiveDocument.Bookmarks.Count

I've tried using names also:
ActiveDocument.Bookmarks("bkfont").Range.Font.Italic = False
ActiveDocument.Bookmarks("bkfont").Range.Text = "This should not be
italics."

Using either the number 1 or the name is providing the same results:
Sometimes it works, then it doesn't.
I'm trying to figure out what makes it work.

I realize that in a typical document you need to consider multiple
bookmarks.

The project has the title "Manager's Name:" in italics.
I want to insert the actual managers name at the bookmark, in non-italics.

Thanks,
George
 
M

mksmith

George

When it doesn't work where is the bookmark placed? Is it somewhere
special such as in a header or whatever?

Malc
 
G

George Seese

Malc,
No header.
The only thing in the document is what I stated:
The words "Managers' Name: " in italics. Then a bookmark. To keep it simple
and focus on the problem.
After you insert a placeholder bookmark, you can't move it, right? I've
tried different locations and every time needed to delete and add.
I've tried to be consistent in testing, to keep "all other things equal",
but have not established a difference pattern yet.
George
 
D

Dave Lett

Hi George,

You've put your finger right on it. You're using a placeholder bookmark, not
an enclosing bookmark. Therefore, the text that you put in at the bookmark,
with something like

ActiveDocument.Bookmarks("Test").Range.text = "Test"

is never eclosed by the bookmarks. Instead, it is inserted _after_ the
placeholder bookmark. To make the placeholder bookmark an enclosing
bookmark, you'd have to do something like the following:

Dim sString As String
Dim oRng As Range
sString = "Test"
ActiveDocument.Bookmarks("Test").Range.text = sString
Set oRng = ActiveDocument.Range _
(Start:=ActiveDocument.Bookmarks("Test").Range.Start, _
End:=ActiveDocument.Bookmarks("Test").Range.Start + Len(sString))
ActiveDocument.Bookmarks.Add _
Name:="Test", _
Range:=oRng

HTH
 

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