Underline bookmarked text

B

Bigfoot17

Thanks to this group (a prior post) I have been able to place text into a
Word template using the method (partially) listed below. But I would like the
placed text to be underlined. If I insert a ".font.underline=true" or
".font.underline=wdUnderlineSingle" I get nowhere.

Thank you for any assistance. And on this Memorial Day weekend thank you
for those who have served America.

Private Sub CommandButton1_Click()
With ActiveDocument
.Bookmarks ("RecipientName").Range _
.InsertBefore TextBox1
.Bookmarks("RecipientReturnAddress").Range _
.InsertBefore TextBox2
.Bookmarks("RecipientCSZ").Range _
.InsertBefore TextBox3
.Bookmarks("ReferenceNo").Range _
....
 
H

Helmut Weber

Hi Bigfoot17,

like that:

Sub Test9087()
' for including bookmarks like [bookmark]
Dim strTmp As String
Dim i As Long
strTmp = "xxxxx"
With ActiveDocument
.Bookmarks("Test").Range _
.InsertBefore strTmp
For i = 1 To Len(strTmp)
.Bookmarks("Test").Range. _
Characters(i).Font.Underline = wdUnderlineSingle
Next
End With
End Sub

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
B

Bigfoot17

Thank you

I'd like to followup with a related question. I have what I call some
'conditional paragraphs'. If in the Userform Check boxes are checked then
some lengthy paragraphs are added to the Word document. (A mock sample is
below).

First - somone may have a suggestions on how to do this.
Second - how would I underline the words Emergency Broadcast and how would I
underline the TextBox25?

If CheckBox1 = True And CheckBox2 = True Or CheckBox2 = True Then
sc2 = sc2 & Chr(10) & "This is a test of the Emergency Broadcast
System, had it been an actual emergency you would have been directed..." &
Chr(10) & Chr(10) _
& "Four score and seven years ago our" & TextBox25 & " brought forth
on this continent an new nation ..." & Chr(10) & Chr(10) _
& "The only thing needed for evil to prevail is for good men to do
nothing." & Chr(10) & Chr(10) _
& "Another parargraph" & Chr(10) & Chr(10) _
& "Yet another paragraph" & Chr(10) & Chr(10)
End If
 
B

Bigfoot17

Thank you

I'd like to followup with a related question. I have what I call some
'conditional paragraphs'. If in the Userform Check boxes are checked then
some lengthy paragraphs are added to the Word document. (A mock sample is
below).

First - somone may have a suggestions on how to do this.
Second - how would I underline the words Emergency Broadcast and how would I
underline the TextBox25?

If CheckBox1 = True And CheckBox2 = True Or CheckBox2 = True Then
sc2 = sc2 & Chr(10) & "This is a test of the Emergency Broadcast
System, had it been an actual emergency you would have been directed..." &
Chr(10) & Chr(10) _
& "Four score and seven years ago our" & TextBox25 & " brought forth
on this continent an new nation ..." & Chr(10) & Chr(10) _
& "The only thing needed for evil to prevail is for good men to do
nothing." & Chr(10) & Chr(10) _
& "Another parargraph" & Chr(10) & Chr(10) _
& "Yet another paragraph" & Chr(10) & Chr(10)
End If
 
H

Helmut Weber

Hi Bigfoot17,

i'm sorry, other attempts didn't work,
and sure there are many ways of improvement and streamlining:

Sub CommandButton4_Click()
Dim sc2 As String
Dim rTmp As Range
Set rTmp = Selection.Range
sc2 = Chr(10) & "This is a test of the Emergency Broadcast " _
& TextBox1 & " some more text" & Chr(10)
Selection.Collapse
Selection.Bookmarks.Add "Test"
Selection.Bookmarks("Test").Range.Text = sc2
Selection.Bookmarks.Add "Test1"
rTmp.start = ActiveDocument.Bookmarks("Test").start
rTmp.End = ActiveDocument.Bookmarks("Test1").End
With rTmp.Find
.Text = "test"
If .Execute Then
rTmp.Font.Underline = wdUnderlineSingle
End If
End With
rTmp.start = ActiveDocument.Bookmarks("Test").start
rTmp.End = ActiveDocument.Bookmarks("Test1").End
With rTmp.Find
.Text = "Emergency"
If .Execute Then
rTmp.Font.Underline = wdUnderlineSingle
End If
End With
rTmp.start = ActiveDocument.Bookmarks("Test").start
rTmp.End = ActiveDocument.Bookmarks("Test1").End
With rTmp.Find
.Text = TextBox1.Text
If .Execute Then
rTmp.Font.Underline = wdUnderlineSingle
End If
End With

End Sub

Note, that you won't see the result,
before the userform is closed.

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
B

Bigfoot17

Sorry I was not clear. You previous help was great, and appreciated, I am
now able to underline bookmarked text. That triggered my second related
questions of underlining text within a string. Now I am off to learn from
your 2nd response.
 

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