title: MS Word VBA - Inserting Text into Header with Different Styles
body: <p>Using VBA I'm able to insert text in a Word document header:</p>
  
  <pre><code>Set HeaderRange = ActiveDocument.Sections.Item(1).Headers(wdHeaderFooterPrimary).Range
  
  HeaderRange.Text = "header text'
  </code></pre>
  
  <p>But I want to be able to add multiple lines of text to the header, each with it's own style applied to it.</p>
  
  <p>One way I found to do it was as follows:</p>
  
  <pre><code>Set HeaderRange = ActiveDocument.Sections.Item(1).Headers(wdHeaderFooterPrimary).Range
  
  HeaderRange.Text = "Line One Text" &amp; vbNewLine &amp; "Line Two Text"  &amp; vbNewLine &amp; "Line Three Text"
  
  ' set the ranges based on sentences
  Set NameRange = HeaderRange.Sentences(1)
  Set TitleRange = HeaderRange.Sentences(2)
  Set AddressRange = HeaderRange.Sentences(3)
  
  ' set the styles for each part
  NameRange.Style = "title"
  TitleRange.Style = "strong"
  AddressRange.Style = "emphasis"
  </code></pre>
  
  <p>That basically works, but if there is a period (.) anywhere in one of the lines of text, that causes a problem.  </p>
  
  <p>Is there a better way that I can delimit the text to put into the header into multiple parts and apply a different style to each part? </p>