question

MacProCT-9603 avatar image
0 Votes"
MacProCT-9603 asked MacProCT-9603 commented

2021 Word for Mac doesn't like Macro, error 4198

We just bought Office 2021 for Mac as a download and installed it with latest installer and ran the one pending update.

Then we tried using the Macro that we've been using for about a decade just fine with Word 2011.

We get run-time error 4198 and when I click debug the line of the Macro that its getting hung up on is: "ActiveWindow.ActivePane.View.SeekView" "wdSeekCurrentPageHeader"

The person who created this Macro is no longer with us and I don't have the knowledge to fix it. Hoping one of you will be willing to review it and find the glitch. Thank you.

I'm going to paste the Macro below, but if it gets garbled, you can see the Macro in my Dropbox:

https://www.dropbox.com/s/80dyd6e67dfxrp2/drummer-macro.txt?dl=0

dropbox dot com/s/80dyd6e67dfxrp2/drummer-macro.txt?dl=0


~~~~~ Macro begins ~~~~~

Sub Drummer()
'
' Drummer Macro
' Macro recorded 5/7/06 by Office User
'
Selection.WholeStory
Selection.Style = ActiveDocument.Styles("Body Text")
Selection.Font.Name = "Times"
Selection.Font.Size = 11
With ActiveDocument.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientPortrait
.TopMargin = InchesToPoints(1)
.BottomMargin = InchesToPoints(1)
.LeftMargin = InchesToPoints(1)
.RightMargin = InchesToPoints(1)
.Gutter = InchesToPoints(0)
.HeaderDistance = InchesToPoints(0.5)
.FooterDistance = InchesToPoints(0.5)
.PageWidth = InchesToPoints(8.5)
.PageHeight = InchesToPoints(11)
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = True
.MirrorMargins = False
End With
With Selection.ParagraphFormat
.LeftIndent = InchesToPoints(0)
.RightIndent = InchesToPoints(0)
.SpaceBefore = 0
.SpaceAfter = 0
.LineSpacingRule = wdLineSpaceSingle
.Alignment = wdAlignParagraphJustify
.WidowControl = True
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = InchesToPoints(0.1)
.OutlineLevel = wdOutlineLevelBodyText
End With
With Selection.Font
.Name = "Times"
.Size = 11
.Italic = False
.Underline = wdUnderlineNone
.UnderlineColor = wdColorAutomatic
.StrikeThrough = False
.DoubleStrikeThrough = False
.Outline = False
.Emboss = False
.Shadow = False
.Hidden = False
.SmallCaps = False
.AllCaps = False
.Color = wdColorAutomatic
.Engrave = False
.Superscript = False
.Subscript = False
.Spacing = 0
.Scaling = 100
.Position = 0
.Kerning = 0
.Animation = wdAnimationNone
End With
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^t"
.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.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = " ^p"
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^p^p"
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting

   With Selection.Find
     .Text = " A.M."
     .Replacement.Text = " a.m."
     .Forward = True
     .Wrap = wdFindAsk
     .Format = False
     .MatchCase = True
     .MatchWholeWord = False
     .MatchWildcards = False
     .MatchSoundsLike = False
     .MatchAllWordForms = False
 End With
     Selection.Find.Execute Replace:=wdReplaceAll

With Selection.Find
.Text = " am."
.Replacement.Text = " a.m."
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = " P.M."
.Replacement.Text = " p.m."
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = True
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = " pm"
.Replacement.Text = " p.m."
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = " pm."
.Replacement.Text = " p.m."
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ":00"
.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

With Selection.Find
.Text = ".00"
.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
With Selection.Find
.Text = " Sun."
.Replacement.Text = " Sunday"
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "Mon."
.Replacement.Text = "Monday"
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "Tues."
.Replacement.Text = "Tuesday"
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "Wed."
.Replacement.Text = "Wednesday"
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "Thurs."
.Replacement.Text = "Thursday"
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "Thur."
.Replacement.Text = "Thursday"
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

 With Selection.Find
     .Text = "Fri."
     .Replacement.Text = "Friday"
     .Forward = True
     .Wrap = wdFindAsk
     .Format = False
     .MatchCase = False
     .MatchWholeWord = False
     .MatchWildcards = False
     .MatchSoundsLike = False
     .MatchAllWordForms = False
 End With
 Selection.Find.Execute Replace:=wdReplaceAll
 With Selection.Find
     .Text = " Sat."
     .Replacement.Text = " Saturday"
     .Forward = True
     .Wrap = wdFindAsk
     .Format = False
     .MatchCase = True
     .MatchWholeWord = False
     .MatchWildcards = False
     .MatchSoundsLike = False
     .MatchAllWordForms = False
 End With
 Selection.Find.Execute Replace:=wdReplaceAll
 With Selection.Find
     .Text = " Rd."
     .Replacement.Text = " Road"
     .Forward = True
     .Wrap = wdFindAsk
     .Format = False
     .MatchCase = True
     .MatchWholeWord = False
     .MatchWildcards = False
     .MatchSoundsLike = False
     .MatchAllWordForms = False
 End With
 Selection.Find.Execute Replace:=wdReplaceAll
 With Selection.Find
     .Text = "%"
     .Replacement.Text = " percent"
     .Forward = True
     .Wrap = wdFindAsk
     .Format = False
     .MatchCase = True
     .MatchWholeWord = False
     .MatchWildcards = False
     .MatchSoundsLike = False
     .MatchAllWordForms = False
 End With
 Selection.Find.Execute Replace:=wdReplaceAll
 With Selection.Find
     .Text = "&"
     .Replacement.Text = " and "
     .Forward = True
     .Wrap = wdFindAsk
     .Format = False
     .MatchCase = True
     .MatchWholeWord = False
     .MatchWildcards = False
     .MatchSoundsLike = False
     .MatchAllWordForms = False
 End With
 Selection.Find.Execute Replace:=wdReplaceAll
 Selection.Find.ClearFormatting
 Selection.Find.Replacement.ClearFormatting
 With Selection.Find
     .Text = "    "
     .Replacement.Text = " "
     .Forward = True
     .Wrap = wdFindAsk
     .Format = False
     .MatchCase = True
     .MatchWholeWord = False
     .MatchWildcards = False
     .MatchSoundsLike = False
     .MatchAllWordForms = False
 End With
 Selection.Find.Execute Replace:=wdReplaceAll
 With Selection.Find
     .Text = "  "
     .Replacement.Text = " "
     .Forward = True
     .Wrap = wdFindAsk
     .Format = False
     .MatchCase = True
     .MatchWholeWord = False
     .MatchWildcards = False
     .MatchSoundsLike = False
     .MatchAllWordForms = False
 End With
 Selection.Find.Execute Replace:=wdReplaceAll
 If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
     ActiveWindow.Panes(2).Close
 End If
 If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
     ActivePane.View.Type = wdOutlineView Or ActiveWindow.ActivePane.View.Type _
      = wdMasterView Then
     ActiveWindow.ActivePane.View.Type = wdPageView
 End If
 ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
 NormalTemplate.AutoTextEntries("Filename").Insert Where:=Selection.Range
 Selection.WholeStory
 Selection.Font.Name = "Times"
 Selection.Font.Size = 11
 Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
 ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument

   
 End Sub

~~~~~End of macro~~~~~

office-vba-devoffice-word-itpro
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

PaulEdstein-6097 avatar image
0 Votes"
PaulEdstein-6097 answered MacProCT-9603 commented

Try:

 Sub Demo()
 Application.ScreenUpdating = False
 With ActiveDocument
   With .PageSetup
     .LineNumbering.Active = False
     .Orientation = wdOrientPortrait
     .TopMargin = InchesToPoints(1)
     .BottomMargin = InchesToPoints(1)
     .LeftMargin = InchesToPoints(1)
     .RightMargin = InchesToPoints(1)
     .Gutter = InchesToPoints(0)
     .HeaderDistance = InchesToPoints(0.5)
     .FooterDistance = InchesToPoints(0.5)
     .PageWidth = InchesToPoints(8.5)
     .PageHeight = InchesToPoints(11)
     .SectionStart = wdSectionNewPage
     .OddAndEvenPagesHeaderFooter = False
     .DifferentFirstPageHeaderFooter = False
     .VerticalAlignment = wdAlignVerticalTop
     .SuppressEndnotes = True
     .MirrorMargins = False
   End With
   With .Styles(wdStyleNormal)
     .ParagraphFormat.Alignment = wdAlignParagraphLeft
     With .Font
       .Name = "Times"
       .Size = 11
     End With
   End With
   .Range.Style = wdStyleBodyText
   With .Styles(wdStyleBodyText)
     With .Font
       .Name = "Times"
       .Size = 11
       .Italic = False
       .Underline = wdUnderlineNone
       .UnderlineColor = wdColorAutomatic
       .StrikeThrough = False
       .DoubleStrikeThrough = False
       .Outline = False
       .Emboss = False
       .Shadow = False
       .Hidden = False
       .SmallCaps = False
       .AllCaps = False
       .Color = wdColorAutomatic
       .Engrave = False
       .Superscript = False
       .Subscript = False
       .Spacing = 0
       .Scaling = 100
       .Position = 0
       .Kerning = 0
       .Animation = wdAnimationNone
     End With
     With .ParagraphFormat
       .LeftIndent = InchesToPoints(0)
       .RightIndent = InchesToPoints(0)
       .SpaceBefore = 0
       .SpaceAfter = 0
       .LineSpacingRule = wdLineSpaceSingle
       .Alignment = wdAlignParagraphJustify
       .WidowControl = True
       .KeepWithNext = False
       .KeepTogether = False
       .PageBreakBefore = False
       .NoLineNumber = False
       .Hyphenation = True
       .FirstLineIndent = InchesToPoints(0.1)
       .OutlineLevel = wdOutlineLevelBodyText
     End With
   End With
   With .Range.Find
     .ClearFormatting
     .Replacement.ClearFormatting
     .Forward = True
     .Wrap = wdFindAsk
     .Format = False
     .MatchWildcards = True
     .Text = "^t"
     .Replacement.Text = ""
     .Execute Replace:=wdReplaceAll
     .Text = "[ ^t]@^13"
     .Replacement.Text = "^p"
     .Execute Replace:=wdReplaceAll
     .Text = "[^13]{2,}"
     .Replacement.Text = "^p"
     .Execute Replace:=wdReplaceAll
     .Text = " A.M."
     .Replacement.Text = " a.m."
     .Execute Replace:=wdReplaceAll
     .Text = " am."
     .Execute Replace:=wdReplaceAll
     .Text = " P.M."
     .Replacement.Text = " p.m."
     .Execute Replace:=wdReplaceAll
     .Text = " pm"
     .Execute Replace:=wdReplaceAll
     .Text = " pm."
     .Execute Replace:=wdReplaceAll
     .Text = "[.:]00"
     .Replacement.Text = ""
     .Execute Replace:=wdReplaceAll
    .Text = "Sun."
     .Replacement.Text = "Sunday"
     .Execute Replace:=wdReplaceAll
     .Text = "Mon."
     .Replacement.Text = "Monday"
     .Execute Replace:=wdReplaceAll
     .Text = "Tues."
     .Replacement.Text = "Tuesday"
     .Execute Replace:=wdReplaceAll
     .Text = "Wed."
     .Replacement.Text = "Wednesday"
     .Execute Replace:=wdReplaceAll
     .Text = "Thurs."
     .Replacement.Text = "Thursday"
     .Execute Replace:=wdReplaceAll
     .Text = "Thur."
     .Replacement.Text = "Thursday"
     .Execute Replace:=wdReplaceAll
     .Text = "Fri."
     .Replacement.Text = "Friday"
     .Execute Replace:=wdReplaceAll
     .Text = "Sat."
     .Replacement.Text = "Saturday"
     .Execute Replace:=wdReplaceAll
     .Text = "Rd."
     .Replacement.Text = "Road"
     .Execute Replace:=wdReplaceAll
     .Text = "%"
     .Replacement.Text = " percent"
     .Execute Replace:=wdReplaceAll
     .Text = "&"
     .Replacement.Text = " and "
     .Execute Replace:=wdReplaceAll
     .Text = "[ ]{2,}"
     .Replacement.Text = " "
     .Execute Replace:=wdReplaceAll
   End With
   With .Sections.First.Headers(wdHeaderFooterPrimary).Range
     .Style = wdStyleNormal
     .Fields.Add Range:=.Characters.Last, Type:=wdFieldEmpty, Text:="FILENAME \p", PreserveFormatting:=False
   End With
 End With
 Application.ScreenUpdating = True
 End Sub

Aside from being much shorter, you should also find the above code far more efficient than what you've been using.



· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks so much, Paul. I look forward to trying it :)

0 Votes 0 ·