Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / May 2008

Tip: Looking for answers? Try searching our database.

Underline bookmarked text

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bigfoot17 - 23 May 2008 16:20 GMT
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 _
...
Helmut Weber - 24 May 2008 01:52 GMT
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
Bigfoot17 - 27 May 2008 14:10 GMT
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
Bigfoot17 - 27 May 2008 14:12 GMT
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
Helmut Weber - 27 May 2008 15:22 GMT
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
Bigfoot17 - 27 May 2008 20:36 GMT
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.

> Hi Bigfoot17,
>
[quoted text clipped - 48 lines]
>
> Vista Small Business, Office XP
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.