Tutorial :How do i make a string bold


I'm creating a word document programatically using VBA.

1) I have a a string with value - "Strategy". I want to make it bold and to be displayed in the word document.

I have tried this below, but the text is never changed:

Dim wrdApp As Word.Application  Dim wrdDoc As Word.Document  Set wrdApp = CreateObject("Word.Application")    Dim strategy As String  strategy = "STRATEGY"  Dim objWdRange As Word.Range      wrdApp.Visible = True  Set wrdDoc = wrdApp.Documents.Open("C:\Program Files\DailyStrategy.doc")      With wrdDoc      If wrdDoc.Bookmarks.Exists("MarketCommentry") Then          wrdDoc.Bookmarks("MarketCommentry").Range.Text =  strategy         Set objWdRange = wrdDoc.Content       With objWdRange.Find          .ClearFormatting          .Replacement.ClearFormatting          .Text = "STRATEGY"            'Make found bold and italic          With .Replacement.Font              .Bold = True              .Italic = True          End With          .Execute Replace:=wdReplaceAll      End With  End With  

End If regards



EDIT:: I should have better tried in the VBA debugger first, which I did now. This one should work:

With wrdDoc     Set objWdRange = wrdDoc.Content      With objWdRange.Find         .ClearFormatting         .Text = "STRATEGY"         .Execute Replace:=wdReplaceNone     End With  End With    If objWdRange.Find.Found Then    'Make found bold and italic    With objWdRange.Font         .Bold = True        .Italic = True    End With  End If  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »