Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Need to bold a line in Word document

Posted on 2008-10-21
2
Medium Priority
?
332 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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

963 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