title: How to use VBA to convert text in Microsoft Word
body: <p>I want all our old Word documents at the Uni to start to have accessible styles applied. For this test, I want to set up a macro to search a Word doc and wherever it finds 11pt Arial, I want it to apply an Accessible Style which will be Verdana 11pt. In doing this, it means academic staff could more easily convert non-accessible documents into more accessible documents.</p>
  
  <p>I've started learning macro and can create one which saves the Word file out to PDF, which is a useful shortcut but I'm struggling.</p>
  
  <p>I've tried creating a macro to open Replace, look for any instances of Arial 11pt and then replace them all with another style, but when I run it, it seems to apply my alternative style but also adds weird boxes to the document.</p>
  
  <p>Also, if I apply the Header Style to the doc and then manually edit that style to be Arial 11pt then when I run the macro, the text seems to get the new Style applied but what I see is still Arial, and I get the weird boxes!</p>
  
  <p>I would love to crack this on my own but it's not an area I am familiar with so any help from the community would be fantastic.</p>
  
  <p>Here's the macro code, which I created using the recorder:</p>
  
  <pre><code>Sub Style()
  '
  ' Style Macro
  '
      Selection.Find.ClearFormatting
      With Selection.Find.Font
          .Size = 11
          .Bold = False
          .Italic = False
      End With
      Selection.Find.Replacement.ClearFormatting
      Selection.Find.Replacement.Style = ActiveDocument.Styles("Written Stuff")
      With Selection.Find.Replacement.ParagraphFormat
          With .Shading
              .Texture = wdTextureNone
              .ForegroundPatternColor = wdColorBlack
              .BackgroundPatternColor = wdColorBlack
          End With
          .Borders.Shadow = False
      End With
      With Selection.Find
          .Text = ""
          .Replacement.Text = ""
          .Forward = True
          .Wrap = wdFindContinue
          .Format = True
          .MatchCase = False
          .MatchWholeWord = False
          .MatchWildcards = False
          .MatchSoundsLike = False
          .MatchAllWordForms = False
      End With
      Selection.Find.Execute Replace:=wdReplaceAll
  End Sub
  </code></pre>
  
  <p>In this example, instead of using Verdana I'm using Algeria so I can more easily see the font changes.</p>