Solved

Need to bold a line in Word document

Posted on 2008-10-21
2
321 Views
Last Modified: 2012-05-05
Experts -

Using vb.net, Word 2003, not quite sure why the following function isn't working.  The do while evaluates to true, but it passes right over the with clause. I use something almost identical to find and delete an entire line, so I'm not quite sure what's going on. BTW, I want to find the text "Your Ref:", and then bold the entire line where this string resides; also, it always resides at the beginning of the line.

 Sub BoldYourRef(ByVal doc As Object)

        Dim wdApp As Object 'Word.Application
        Dim Unit1 As Microsoft.Office.Interop.Word.WdUnits = Microsoft.Office.Interop.Word.WdUnits.wdLine
        wdApp = doc.Application
        doc.Range.Select()
        wdApp.Selection.Find.Text = "Your Ref:"
        Do While wdApp.Selection.Find.Execute(FindText:="Your Ref:", Forward:=True, _
                    Format:=True) = True
           With wdApp.Selection
             wdApp.Selection.Expand(Unit1)
             wdApp.selection.Font.Bold = True
            End With
        Loop
    End Sub


TIA
crafuse
0
Comment
Question by:crafuse
2 Comments
 
LVL 23

Accepted Solution

by:
irudyk earned 500 total points
ID: 22768778
Does something like the following work for you?
Sub BoldYourRef(ByVal doc As Object)
    Dim wdApp As Object 'Word.Application
    Dim Unit1 As Microsoft.Office.Interop.Word.WdUnits = Microsoft.Office.Interop.Word.WdUnits.wdLine
    wdApp = doc.Application
    wdApp.Selection.HomeKey(6)
    wdApp.Selection.Find.Text = "Your Ref:"
    Do While wdApp.Selection.Find.Execute(FindText:="Your Ref:", Forward:=True, Format:=True) = True
        With wdApp.Selection
            wdApp.Selection.Expand(Unit1)
            wdApp.selection.Font.Bold = True
            wdApp.Selection.Collapse(0)
        End With
    Loop
End Sub

Open in new window

0
 

Author Closing Comment

by:crafuse
ID: 31508329
sweet. beautiful. great. and awesome.

thanks!
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question