V
VBA Coder
Can anyone tell me if this can be done. With VBA code, I want to add some
text to a bookmark within my document but as I am adding the text to the
bookmark, I'd like to turn on/off Bold, add Underline, add comments, etc...
I am able to do this outside of a bookmark with the Selection method, but
wanted to know if I can do this with a bookmark.
My sample code to format the text of a selection is below, which I would
like to be able to do the same thing for a bookmark:
With Selection
.TypeText Text:="This is my first paragraph"
.TypeParagraph
.TypeText Text:="This is my 2nd paragraph. Now I will "
.Font.Bold = True
.TypeText "BOLD some words. "
.Font.Bold = False
.TypeText Text:="Bold is now turned OFF. Now, add a comment
here"
.Comments.Add Selection.Range, "This is my comment"
.TypeParagraph
.TypeText Text:="This is my 3rd paragraph."
.EndKey unit:=wdLine
End With
Is this possible to do with a bookmark? My code to select the bookmark is:
ActiveDocument.Bookmarks("myBookmark").Select
If I try the same thing using my bookmark, as I did in my above example, the
text gets put after the bookmark, not within the bookmark. And, if I rerun
my code over and over, I get repeating paragraphs, because the bookmark does
not get cleared out, since my sample text is actually in the document, not
within the bookmark.
text to a bookmark within my document but as I am adding the text to the
bookmark, I'd like to turn on/off Bold, add Underline, add comments, etc...
I am able to do this outside of a bookmark with the Selection method, but
wanted to know if I can do this with a bookmark.
My sample code to format the text of a selection is below, which I would
like to be able to do the same thing for a bookmark:
With Selection
.TypeText Text:="This is my first paragraph"
.TypeParagraph
.TypeText Text:="This is my 2nd paragraph. Now I will "
.Font.Bold = True
.TypeText "BOLD some words. "
.Font.Bold = False
.TypeText Text:="Bold is now turned OFF. Now, add a comment
here"
.Comments.Add Selection.Range, "This is my comment"
.TypeParagraph
.TypeText Text:="This is my 3rd paragraph."
.EndKey unit:=wdLine
End With
Is this possible to do with a bookmark? My code to select the bookmark is:
ActiveDocument.Bookmarks("myBookmark").Select
If I try the same thing using my bookmark, as I did in my above example, the
text gets put after the bookmark, not within the bookmark. And, if I rerun
my code over and over, I get repeating paragraphs, because the bookmark does
not get cleared out, since my sample text is actually in the document, not
within the bookmark.