0

My uncle has been working with a WordBasic template and cannot update his computer. He is running the macro on Word 2011. When trying to add the macro to Word 365 we receive the following error message: Run time error '102'

When debugging we receive the error in the command MatchCase

WordBasic.EditReplaceStyle Style:="Título 5"
WordBasic.WW2_EditReplace Find:="", Replace:="", WholeWord:=0, _
MatchCase:=0, Format:=1, ReplaceAll:=1
WordBasic.EditFindStyle Style:="Título 2"

This is the first of maybe a lot of errors, so i want to start with the right foot. Than

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
  • You may benefit from recording a macro that does what your snippet of code does to see how to do it in VBA. – braX Jul 01 '21 at 04:55
  • Wordbasic was prior Word97 you need to move on to VBA. See [Converting WordBasic Macros to Visual Basic](https://learn.microsoft.com/en-us/previous-versions/office/developer/office-2003/aa211926(v=office.11)?redirectedfrom=MSDN) – Pᴇʜ Jul 01 '21 at 06:18

1 Answers1

1

Your uncle's macro is a just doing a find and replace. The replacement VBA code can be something like this:

Sub FindReplaceHeading2()
    With ActiveDocument.Content.Find
        .ClearFormatting
        .Style = ActiveDocument.Styles(wdStyleHeading2)
        .Replacement.ClearFormatting
        .Replacement.Style = ActiveDocument.Styles(wdStyleHeading5)
        .Text = ""
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindStop
        .Format = True
        .Execute Replace:=wdReplaceAll
    End With
End Sub
Timothy Rylatt
  • 7,221
  • 2
  • 10
  • 14