title: Word document formatting using vba
body: <p>I have a document with the current formating </p>
  
  <hr>
  
  <p>Title</p>
  
  <p>Subtitle</p>
  
  <p><strong>H1</strong></p>
  
  <p>SampleText SampleText SampleText SampleText
  SampleText SampleText SampleText SampleText
  SampleText SampleText SampleText SampleText</p>
  
  <p><strong>H2</strong></p>
  
  <p>SampleText SampleText SampleText SampleText
  SampleText SampleText SampleText SampleText
  SampleText SampleText SampleText SampleText</p>
  
  <p><strong>H3</strong></p>
  
  <p>SampleText SampleText SampleText SampleText
  SampleText SampleText SampleText SampleText
  SampleText SampleText SampleText SampleText</p>
  
  <p><strong>H4</strong></p>
  
  <p>SampleText SampleText SampleText SampleText
  SampleText SampleText SampleText SampleText
  SampleText SampleText SampleText SampleText</p>
  
  <hr>
  
  <p>here the para headings H1,H2,H3,H4 are bold
  i have just put sample text in place of the pragraph that appears below the heading </p>
  
  <p>I need that doc to be formated to</p>
  
  <hr>
  
  <p>Title Subtitle</p>
  
  <ul>
  <li>H1: SampleText SampleText SampleText SampleText SampleText SampleTextSampleTextSampleText SampleText SampleText SampleText SampleText(para1)</li>
  <li>H2: SampleText SampleText SampleText SampleText SampleText SampleText
    SampleText SampleText SampleText SampleText SampleText SampleText(para2)</li>
  <li>H3: SampleText SampleText SampleText SampleText SampleText SampleText
  SampleText SampleText SampleText SampleText SampleText SampleText(para3)</li>
  <li>H4: SampleText SampleText SampleText SampleText SampleText SampleText
  SampleText SampleText SampleText SampleText SampleText SampleText(para4)</li>
  </ul>
  
  <hr>
  
  <p>Currently i am adding a * to the start of the heading and a colon at the end. Using them as reference i am formating the paragraphs.
  here's the code that i am currently pondering on</p>
  
  <pre><code>    Sub wordfor()
      Dim oRng As Word.Range
      Dim flag As Integer
      Set oRng = ActiveDocument.Content
  
  With oRng.Find
     .ClearFormatting
     .Text = ""
     .Font.Bold = True
          While .Execute
             oRng.Text = "*" + oRng.Text
             oRng.Font.Underline = True
             oRng.Text = oRng.Text + ":"
             oRng.Collapse wdCollapseEnd
          Wend
  End With
  Selection.HomeKey Unit:=wdStory
  Do Until Selection.Information(wdFirstCharacterLineNumber) =   ThisDocument.BuiltInDocumentProperties("Number of lines").Value
  'MsgBox (ThisDocument.BuiltInDocumentProperties("Number of lines").Value)
       Selection.HomeKey Unit:=wdLine
       Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
       If Selection.Text = "*" Then
           Selection.EndKey Unit:=wdLine
           Selection.TypeText Text:=" "
           Selection.Delete Unit:=wdCharacter, Count:=1
  
         Else
         Selection.MoveUp Unit:=wdLine, Count:=1
         Selection.EndKey Unit:=wdLine
         Selection.TypeText Text:=" "
         Selection.Delete Unit:=wdCharacter, Count:=1
         End If
  Selection.MoveDown Unit:=wdLine, Count:=1
   Selection.MoveDown Unit:=wdLine, Count:=1
    Loop
      Selection.MoveUp Unit:=wdLine, Count:=1
           Selection.EndKey Unit:=wdLine
           Selection.TypeText Text:=" "
           Selection.Delete Unit:=wdCharacter, Count:=1
       Selection.HomeKey Unit:=wdStory
      With Selection.Find
          .Text = "*"
          .Replacement.Text = " "
          .Forward = True
          .Wrap = wdFindAsk
          .Format = False
          .MatchCase = False
          .MatchWholeWord = False
          .MatchWildcards = False
          .MatchSoundsLike = False
          .MatchAllWordForms = False
       End With
  Selection.Find.Execute Replace:=wdReplaceAll
  
  Selection.HomeKey Unit:=wdStory
  Selection.EndKey Unit:=wdLine, Extend:=wdExtend
  Selection.Font.Bold = wdToggle
  Selection.EndKey Unit:=wdLine
  Selection.TypeParagraph
  Selection.MoveDown Unit:=wdLine, Count:=1
  Selection.EndKey Unit:=wdStory, Extend:=wdExtend
  With ListGalleries(wdBulletGallery).ListTemplates(1).ListLevels(1)
      .NumberFormat = ChrW(61623)
      .TrailingCharacter = wdTrailingTab
      .NumberStyle = wdListNumberStyleBullet
      .NumberPosition = InchesToPoints(0.25)
      .Alignment = wdListLevelAlignLeft
      .TextPosition = InchesToPoints(0.5)
      .TabPosition = InchesToPoints(0.5)
      .ResetOnHigher = 0
      .StartAt = 1
      With .Font
          .Bold = wdUndefined
          .Italic = wdUndefined
          .StrikeThrough = wdUndefined
          .Subscript = wdUndefined
          .Superscript = wdUndefined
          .Shadow = wdUndefined
          .Outline = wdUndefined
          .Emboss = wdUndefined
          .Engrave = wdUndefined
          .AllCaps = wdUndefined
          .Hidden = wdUndefined
          .Underline = wdUndefined
          .Color = wdUndefined
          .Size = wdUndefined
          .Animation = wdUndefined
          .DoubleStrikeThrough = wdUndefined
          .Name = "Symbol"
      End With
      .LinkedStyle = ""
  End With
  ListGalleries(wdBulletGallery).ListTemplates(1).Name = ""
  Selection.Range.ListFormat.ApplyListTemplate ListTemplate:=ListGalleries( _
      wdBulletGallery).ListTemplates(1), ContinuePreviousList:=False, ApplyTo:= _
      wdListApplyToWholeList, DefaultListBehavior:=wdWord10ListBehavior
  
  End Sub
  </code></pre>
  
  <p>But the code is going into an infinite loop.</p>