none
Converting RichText Controls into legacy text boxes? RRS feed

  • Question

  • A coworker has asked me a favor knowing I play in VBA. However, I do Excel, Access, and Publisher... I barely play in word. I said I'd look into his problem but can't make promises since Word is something I rarely play in.

     

    He made the mistake of creating a restricted form in Word 2010 format and making the input fields Rich Text Controls. However, he needs to convert the 72 files into Word 2003 format and the hundreds of Rich Text controls in each one are not supported. I said I'd look into making a loop that would grab the content of each control, delete it, and replace it with a legacy control, if it's possible. He also provided me with a template with legacy controls if I wanted to go the template route.

     

    I created the loop to open each file, that was easy. However, I don't know anything about Word other than tables. Is it really possible to loop through each rich text field and turn it into a legacy field, somehow?

    Monday, November 21, 2011 10:14 PM

Answers

  • Something along this line:

    Sub ScratchMacro()
    'A quick macro scratch pad created by Greg Maxey
    Dim oCC As ContentControl
    Dim oRng As Word.Range
    Dim strValue As String
    Dim oFF As FormField
    For Each oCC In ActiveDocument.ContentControls
      Set oRng = oCC.Range
      strValue = oRng.Text
      oCC.Delete
      Set oFF = ActiveDocument.FormFields.Add(oRng, wdFieldFormTextInput)
      oFF.Result = strValue
    Next oCC
     
    End Sub


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm
    • Marked as answer by RacerRex9727 Tuesday, November 22, 2011 8:19 PM
    Monday, November 21, 2011 11:26 PM

All replies

  • Something along this line:

    Sub ScratchMacro()
    'A quick macro scratch pad created by Greg Maxey
    Dim oCC As ContentControl
    Dim oRng As Word.Range
    Dim strValue As String
    Dim oFF As FormField
    For Each oCC In ActiveDocument.ContentControls
      Set oRng = oCC.Range
      strValue = oRng.Text
      oCC.Delete
      Set oFF = ActiveDocument.FormFields.Add(oRng, wdFieldFormTextInput)
      oFF.Result = strValue
    Next oCC
     
    End Sub


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm
    • Marked as answer by RacerRex9727 Tuesday, November 22, 2011 8:19 PM
    Monday, November 21, 2011 11:26 PM
  • Thanks Greg! It worked really well when I put it inside my loop. FYI it occasionally didn't like the content of a formfield and didn't transfer the value over, but I just used "on error resume next" to skip over it. My coworker has no problem proofreading each document and making a manual edit here and there. He's just happy the fields are all converted and that 98% of the textinputs carried over. Saved him a ton of work.

    Tuesday, November 22, 2011 8:22 PM