Please see my last post under "Inserting variables in multiple bookmarks". I
have set the range and selected the range, but I still cannot get the text to
be formatted as indicated. I am trying to go to a specific bookmark and
insert and format the text. The last If..End If statement is to delete the
line in the document if there is no text for that line.
Any help would be appreciated. Thank you!
Am an neither Jezebel or Helmut so it that matters then disregard.
Sub Test()
Dim bBkm As String
Dim bText As String
Dim bIndex As Long
For bIndex = 1 To 5
Dim oRng As Range
bBkm = Choose(bIndex, "ReportAddress1", "ReportAddress2",
"ReportAddress3", "ReportAddress4", "ReportAddress5")
bText = Choose(bIndex, ReportAddress1$, ReportAddress2$,
ReportAddress3$, ReportAddress4$, ReportAddress5$)
Set oRng = ActiveDocument.Bookmarks(bBkm).Range
oRng.Text = bText
If bIndex = 4 Or bIndex = 5 Then
oRng.Paragraphs.Style = "Body Text"
End If
If bIndex = 1 Then
oRng.Font.AllCaps = True
End If
If bIndex = (4 Or bIndex = 5) And Len(bText) = 0 Then
oRng.Delete Count:=1
End If
Next
End Sub
singeredel - 28 Feb 2005 17:15 GMT
Greg -- Thank you! I was more than happy to get your response. Everything
that you had worked with one exception, the last set of instructions
regarding deleting the line: Although when stepping through the code, it
showed that bIndex was = 5 and Len(bText) was =0, it skipped over the
oRng.Delete to the End If, so the line was not deleted. I don't understand
why the next step was skipped when all the criteria were met.
> Am an neither Jezebel or Helmut so it that matters then disregard.
>
[quoted text clipped - 22 lines]
> Next
> End Sub
Hi (firstname?),
there are two kinds of bookmarks,
short ones similar to ][, and long ones [Bookmark Text],
which behave very differently.
Short Bookmarks
cannot be deleted by typing backspace
don't have a range.text, in a way
ActiveDocument.Bookmarks("Short").Range.Text = "xxx"
MsgBox ActiveDocument.Bookmarks("Short").Range.Text ' ""
MsgBox Len(ActiveDocument.Bookmarks("Short").Range.Text) ' 0
are still there after assigning text to their range
ActiveDocument.Bookmarks("Short").Range.Text = "xxx"
MsgBox ActiveDocument.Bookmarks.Exists("Short")
Long Bookmarks
can be deleted by typing backspace
have a range text
vanish after assigning text to their range !!!
MsgBox ActiveDocument.Bookmarks("Long").Range.Text
MsgBox Len(ActiveDocument.Bookmarks("Long").Range.Text)
ActiveDocument.Bookmarks("Long").Range.Text = "longlong"
MsgBox ActiveDocument.Bookmarks.Exists("Long") ' false !!!
Don't give up, ca all be handled!
What kind of bookmarks do you use?
I don't hope both kinds.
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
singeredel - 28 Feb 2005 16:53 GMT
I didn't know there was more than one kind of bookmark, but they do go away
when I backspace, but they do not disappear when I place text there, as I can
still see the bookmark indicator in the document.
> Hi (firstname?),
>
[quoted text clipped - 30 lines]
> Word XP, Win 98
> http://word.mvps.org/
Helmut Weber - 28 Feb 2005 17:25 GMT
Hi (firstname?),
(would really be nice to be on confident terms,
no MVP here hides his name,)
Sub test9999()
Dim s As String ' text to be inserted
Dim l As Long ' lenght of that text
Dim r As Range ' the range which that text occupies
Set r = Selection.Range ' initializing the range
' other methods of coding possible
s = "Text In Capitals"
l = Len(s)
' add text from the bookmark on
ActiveDocument.Bookmarks("Short2").Range.Text = s
' get the range of the inserted text
r.Start = ActiveDocument.Bookmarks("Short2").Range.Start
' extend the range according to the lenght
' of the inserted text
r.End = r.Start + l
r.Font.AllCaps = True
End Sub
HTH
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
singeredel - 28 Feb 2005 18:09 GMT
Hi Helmut. My name is Julie. Please excuse my etiquette. I am new to these
forums and am not aware of all the formalities. Thank you so much for your
help!
> Hi (firstname?),
> (would really be nice to be on confident terms,
[quoted text clipped - 26 lines]
> Word XP, Win 98
> http://word.mvps.org/