Making text bold using wdDoc.Content

mecerrato

Board Regular
Joined
Oct 5, 2015
Messages
184
Office Version
  1. 365
Platform
  1. Windows
HI, I am a rookie VBA coder, I use it to automate work for myself :-)

I have this piece of code that is part of a larger routine, all works but I would like to make some text bold and underlined and some normal.

VBA Code:
    With wdDoc.Content
        '--- paste the range image first, because it overwrites
        '    everything in the document
        
        .PasteAndFormat Type:=wdChartPicture
        .InlineShapes(1).Height = 750
        
        '--- now add our greeting at the start of the email
'        .InsertBefore "See current year production data and current pipeline. " & vbCr & vbCr
        .InsertBefore "Please Review " & vbCr & vbCr ' & vbCr & .Font.Bold & "<u><b>Issue: </u></b>"
                                   
        '--- finally add our sign off after the image
        .InsertAfter vbCr & vbCr & _
                     "Thank you" & vbCr & vbCr
                     
    End With

My end result is for it to look like the sample below, where the word Issue would be bold and underlined and the text under it would not be bold or underlined. I will get the value of the text below the word Issue from a range on my sheet

Issue:
get cosignor

can someone help me with this? I tried a couple of things but really I don't know how to do it.
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
For you reference.
The code is under the WORD VBA.
If you do in the EXCEL VBA or in other WORD documents, you should amend the line "Set wdDoc = ThisDocument" to set wdDoc as what you need.

HTH
VBA Code:
Sub test()
    Dim wdDoc As Document
    Set wdDoc = ThisDocument
    
    Dim myCount

    wdDoc.Content.Paragraphs.Add
    myCount = wdDoc.Content.Paragraphs.Count
    wdDoc.Content.Paragraphs(myCount).Range.Text = "Issue:"
    wdDoc.Content.Paragraphs(myCount).Range.Font.Bold = True
    wdDoc.Content.Paragraphs(myCount).Range.Font.Underline = wdUnderlineSingle
    
    wdDoc.Content.Paragraphs.Add
    myCount = wdDoc.Content.Paragraphs.Count
    wdDoc.Content.Paragraphs(myCount).Range.Text = "get cosignor"
    wdDoc.Content.Paragraphs(myCount).Range.Font.Bold = False
    wdDoc.Content.Paragraphs(myCount).Range.Font.Underline = wdUnderlineNone   
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top