Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need to bold a line in Word document

Posted on 2008-10-21
2
Medium Priority
?
330 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

730 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