title: Making Certain Text Bold In Excel VBA
body: <p>I am exporting an excel table into word using VBA. The word document has one bookmark. The code is such that first it writes the TYPE as the heading and then write all the description under that TYPE. I want the headings to be bold and formatted. I have the following code but it does not work. If anyone could suggest something.  </p>
  
  <pre><code>If Dir(strPath &amp; "\" &amp; strFileName) &lt;&gt; "" Then
  
      'Word Document open
      On Error Resume Next
      Set objWDApp = GetObject(, "Word.Application")
      If objWDApp Is Nothing Then Set objWDApp = CreateObject("Word.Application")
      With objWDApp
          .Visible = True 'Or True, if Word is to be indicated
          .Documents.Open (strPath &amp; "\" &amp; strFileName)
          Set objRng = objWDApp.ActiveDocument.Bookmarks("Bookmark").Range
  
          .Styles.Add ("Heading")
          .Styles.Add ("Text")
  
          With .Styles("Heading").Font
  
              .Name = "Arial"
              .Size = 12
              .Bold = True
              .Underline = True
          End With
  
          With .Styles("Text").Font
  
              .Name = "Arial"
              .Size = 10
              .Bold = False
              .Underline = False
          End With
  
  
      End With
      On Error GoTo 0
  
      i = Start_Cell 
      idx(1) = i 
      n = 2 
      Do ' Search for first empty cell in the table
          i = i + 1
  
  
          If i &gt; Start_Cell + 1 And Cells(i, QB_Type).Value = Cells(i - 1, QB_Type) Then GoTo Loop1
          idx(n) = i
          n = n + 1
  </code></pre>
  
  <p>Loop1:</p>
  
  <pre><code>    Loop Until IsEmpty(Cells(i + 1, QB_Type).Value)
  
  
      idxEnd = i 
      idx(n) = 9999 
  
      i = Start_Cell
      n = 1 
      Do
  
          If i = idx(n) Then
              strTMP = vbNewLine &amp; vbNewLine &amp; Cells(idx(n), QB_Type).Value &amp; vbNewLine 
  
  
                    With objWDApp
  
                 '.Selection.Font.Bold = True 'Type Bold (Doesnt Functions!?)
  
                 .Selection.Styles ("Heading") 'I tried this as well but not functioning...gives an error here that object does not support this property
  
                  WriteToWord objRng, strTMP 'Text written
              End With
              n = n + 1 
          End If
  
          strTMP = vbNewLine &amp; Cells(i, QB_Description).Value &amp; vbNewLine 
          With objWDApp
            '  .Selection.Font.Bold = False 'Description Not bold (Not functioning!?)
            .Selection.Styles("Text") 'This is also not functioning
  
              WriteToWord objRng, strTMP 'Text written
          End With
          i = i + 1 'Arbeitspunktzähler erhöhen
      Loop Until i &gt; idxEnd
  </code></pre>
  
  <p><code>Public Sub WriteToWord(objRng, text)
      With objRng
          .InsertAfter text
      End With
  End Sub</code></p>