Solved

Need to bold a line in Word document

Posted on 2008-10-21
2
319 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

914 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now