MS Word 2016 (Office365) question

zombiemaster

Board Regular
Joined
Oct 27, 2009
Messages
241
I have a Word macro that used to work in Office2007 but we just upgraded to O365 (Office2016) and now it's getting stuck.

I have two Word documents that get color-coded then combined into one Word file and saved to our LAN. The two word docs are named "ID-SUSP-DI" and "ID-SUSP-ZJ" each week and then I run the macro to color/combine them, and it saves the final version into "ID-SUSP-DIZJ".

The code includes this piece that activates the DI version:

'Windows("ID-SUSP-DI").Activate'

And later, after formatting the DI file:

'Windows("ID-SUSP-ZJ").Activate'

To format the ZJ file and copy/paste it into the bottom of the DI version.

Those 'jumping back and forth' pieces no longer work - apparently the new version of Word doesn't allow jumping back and forth between multiple files...

I can run the code and manually switch between the two open Word docs each time the runtime error debugger pops up, and that's what I had to do today to finish the report...but would LOVE IT if someone here knew how to write the code to jump between the two files like we used to be able to do???

Thanks in advance for anybody's help...

~ZM~
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Do you need to activate the documents?

Can't you directly reference them in the code?
 
Upvote 0
Do you need to activate the documents?

Can't you directly reference them in the code?


Yes, that's exactly what I need to do - activate one document, do some formatting, then activate the other, do some formatting, then copy one and paste into bottom of the other one.

This is the code that I was using, that no longer works and hits the debugger every time:

Windows("ID-SUSP-DI").Activate

Windows("ID-SUSP-ZJ").Activate

Do you have any ideas? I sure don't...it worked before upgrading to O365, and now it doesn't...

Thanks,
~ZM~
 
Upvote 0
I'm not sure you need to activate a document to apply formatting but I haven't seen the actual code.

What's happening when you try and activate them?

Are you getting errors? Incorrect results?
 
Upvote 0
Here are the steps that are occurring:
1. I open both files as usual
2. I click the macro button
3. I get this error: Run-time error '5941': The requested member of the collection does not exist.
4. I click Debug
5. It highlights this section:
Code:
Windows("ID-SUSP-DI").Activate
6. I need to activate the ID-SUSP-DI file manually, drag the cursor down to the next VBA step in the VBA Editor and click continue.
7. The macro continues until I get the next error:
Code:
Windows("ID-SUSP-ZJ").Activate
8. I manually activate the ID-SUSP-ZJ file, drag the cursor down to the next VBA step in the Editor and click continue.
9 The same thing happens a couple more times before I get to the end of the VBA and the combined file saves correctly.

Thanks,
~ZM~
 
Upvote 0
Try adding the file extension.
Code:
Windows("ID-SUSP-DI.docx").Activate
 
Upvote 0
Try adding the file extension.
Code:
Windows("ID-SUSP-DI.docx").Activate

Nope, didn't help - I just noticed that these files are in compatibility mode and have the .doc file extension. I tried what you suggested though, and tried both adding the ".doc" into the code (didn't work) then tried saving the files in the newest version as .docx files and then modifying the code to include that too, and that didn't work either...

~ZM~
 
Upvote 0
It would help if you posted the actual code. Office 2016 has no particular issue working with multiple files.
 
Upvote 0
It would help if you posted the actual code. Office 2016 has no particular issue working with multiple files.

Thanks, Paul - I was hesitant about posting the whole thing since it's a bit large and didn't want to confuse anyone with what I was actually having the problem with. But here goes - hopefully I can post this so it shows up correctly. I bolded and underlined each of the places where I get the error and have to skip:

Code:
Sub WeeklySuspense()
'
' Suspense Macro
' This is a newly formatted macro that does all the things I need it to do with little manual intervention now
' Created/modified 2/17/2014 by ~ZM~
'
    [B][U]Windows("ID-SUSP-DI").Activate[/U][/B]
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "AGED SUSPENSE RANGE TOTALS"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    Selection.HomeKey Unit:=wdLine
    Selection.EndKey Unit:=wdStory, Extend:=wdExtend
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.InsertBreak Type:=wdPageBreak
    Selection.HomeKey Unit:=wdLine
    Selection.WholeStory
    Selection.Font.Color = wdColorBlue
    Selection.EndKey Unit:=wdStory
    [B][U]Windows("ID-SUSP-ZJ").Activate[/U][/B]
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "AGED SUSPENSE RANGE TOTALS"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    Selection.HomeKey Unit:=wdLine
    Selection.EndKey Unit:=wdStory, Extend:=wdExtend
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.WholeStory
    Selection.Font.Color = wdColorRed
    Selection.Cut
    [B][U]Windows("ID-SUSP-DI").Activate[/U][/B]
    Selection.PasteAndFormat (wdPasteDefault)

' ----------------------------------------------------------------------------------------------------
' The code below is the original macro for substitution and formatting the combined data

' ID_SUSP Macro
' Macro recorded 7/30/2007 by ~ZM~ - run this to replace the necessary items.
'
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = _
            "0============================================================================================================"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .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 = _
            "============================================================================================================"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = _
            " DI80440B                                           AGED SUSPENSE REPORT                     PAGE: ^#^#^#"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = _
            "^p                                                         ^#^#/^#^#/201#"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = _
            "                                                      CUSTOMAX (DIRECT)"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = _
            "                                                      CUSTOMAX (JV)"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .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 = _
            "                                                  FUNCTION:     "
        .Replacement.Text = " FUNCTION:^t"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = _
            "                                                  FUNCTION:    "
        .Replacement.Text = " FUNCTION:^t"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = _
            "                                                  FUNCTION:   "
        .Replacement.Text = " FUNCTION:^t"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = _
            "                                                  FUNCTION:  "
        .Replacement.Text = " FUNCTION:^t"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = _
            "                                                  FUNCTION: "
        .Replacement.Text = " FUNCTION:^t"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = "                                                  FUNCTION:"
        .Replacement.Text = " FUNCTION:^t"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = _
            "-SERV OFFICE        0-29       30-60       61-90      91-120     121-150     151-180        180+       TOTAL"
        .Replacement.Text = _
            "-SO^t0-29^t30-60^t61-90^t91-120^t121-150^t151-180^t180+^tTOTAL"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = "^p TOTAL"
        .Replacement.Text = "^p TOTAL"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .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 = "^p1^p"
        .Replacement.Text = "^p^p"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.HomeKey Unit:=wdStory
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.WholeStory
    Selection.ParagraphFormat.TabStops.ClearAll
    ActiveDocument.DefaultTabStop = InchesToPoints(1.1)

' IDAgedSusp Macro
' Formats bi weekly aged susp doc - this is where the old one started
'
    With ActiveDocument.PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientLandscape
        .TopMargin = InchesToPoints(0.5)
        .BottomMargin = InchesToPoints(0.5)
        .LeftMargin = InchesToPoints(0.5)
        .RightMargin = InchesToPoints(0.5)
        .Gutter = InchesToPoints(0)
        .HeaderDistance = InchesToPoints(0.3)
        .FooterDistance = InchesToPoints(0.3)
        .PageWidth = InchesToPoints(14)
        .PageHeight = InchesToPoints(8.5)
        .FirstPageTray = wdPrinterDefaultBin
        .OtherPagesTray = wdPrinterDefaultBin
        .SectionStart = wdSectionNewPage
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .VerticalAlignment = wdAlignVerticalTop
        .SuppressEndnotes = False
        .MirrorMargins = False
    End With
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "^p"
        .Replacement.Text = "^t^p"
        .Forward = True
        .Wrap = wdFindContinue
        .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 = "                    "
        .Replacement.Text = "^t"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = "                   "
        .Replacement.Text = "^t"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = "                  "
        .Replacement.Text = "^t"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = "                 "
        .Replacement.Text = "^t"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = "                "
        .Replacement.Text = "^t"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = "               "
        .Replacement.Text = "^t"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = "              "
        .Replacement.Text = "^t"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = "             "
        .Replacement.Text = "^t"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = "            "
        .Replacement.Text = "^t"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = "           "
        .Replacement.Text = "^t"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = "          "
        .Replacement.Text = "^t"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = "         "
        .Replacement.Text = "^t"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = "        "
        .Replacement.Text = "^t"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = "       "
        .Replacement.Text = "^t"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = "      "
        .Replacement.Text = "^t"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = "     "
        .Replacement.Text = "^t"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = "  "
        .Replacement.Text = "^t"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = "^t^p"
        .Replacement.Text = "^p"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "^t============================"
        .Replacement.Text = "^t"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = "^t==============="
        .Replacement.Text = "^t"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = "==="
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = "="
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = "^t^p"
        .Replacement.Text = "^p"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.MoveRight Unit:=wdCharacter, Count:=2, Extend:=wdExtend
    Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "^p0^p"
        .Replacement.Text = "^p^p"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = "^p1^p"
        .Replacement.Text = "^p^p"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    With Selection.Find
        .Text = "^t^t"
        .Replacement.Text = "^t"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    [B][U]Windows("ID-SUSP-ZJ").Activate[/U][/B]
Application.DisplayAlerts = False  ' turns off all alerts
    [B][U]Windows("ID-SUSP-ZJ").Close SaveChanges:=False[/U][/B]
    Selection.TypeText Text:=" "
    ChangeFileOpenDirectory "C:\_MIS FILES\"
    ActiveDocument.SaveAs FileName:="ID-SUSP-DIZJ COMBINED.docx", FileFormat:= _
        wdFormatXMLDocument, LockComments:=False, Password:="", AddToRecentFiles _
        :=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts _
        :=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
        SaveAsAOCELetter:=False
Application.DisplayAlerts = True  ' turns alerts back on


End Sub
 
Upvote 0
Your code mostly looks like it's been created using the macro recorder, which explains the unnecessary window switching. It's also unnecessarily verbose. Try the following. There's a few things like repeated instances of:
Selection.Delete Unit:=wdCharacter, Count:=1
and
Selection.Find.Execute Replace:=wdReplaceAll
I don't understand the need for, so the code may not yet do all that you require of it.
Code:
Sub WeeklySuspense()
Application.ScreenUpdating = False
Dim i As Long, j As Long, k As Long, bDI As Boolean, bZJ As Boolean
bDI = False: bZJ = False
'Loop thru all open docs to find our two
For i = 1 To Documents.Count
  Select Case Split(Documents(i).Name, "doc")(0)
    'Prepare ID-SUSP-DI
    Case "ID-SUSP-DI"
      bDI = True: j = i
      With Documents(i).Range
        With .Find
          .ClearFormatting
          .Text = "AGED SUSPENSE RANGE TOTALS"
          .Replacement.Text = ""
          .Forward = True
          .Wrap = wdFindContinue
          .Format = False
          .MatchCase = False
          .MatchWholeWord = False
          .MatchWildcards = False
          .MatchSoundsLike = False
          .MatchAllWordForms = False
          .Execute
        End With
        If .Find.Found Then
          .Start = .Paragraphs.First.Start
          .End = Documents(i).Range.End
          .Text = Chr(12)
          Documents(i).Range.Font.Color = wdColorBlue
        End If
      End With
    'Prepare ID-SUSP-ZJ
    Case "ID-SUSP-ZJ"
      bZJ = True: k = i
      With Documents(i).Range
        With .Find
          .ClearFormatting
          .Text = "AGED SUSPENSE RANGE TOTALS"
          .Replacement.Text = ""
          .Forward = True
          .Wrap = wdFindContinue
          .Format = False
          .MatchCase = False
          .MatchWholeWord = False
          .MatchWildcards = False
          .MatchSoundsLike = False
          .MatchAllWordForms = False
          .Execute
        End With
        If .Find.Found Then
          .Start = .Paragraphs.First.Start
          .End = Documents(i).Range.End
          .Text = vbNullString
          Documents(i).Range.Font.Color = wdColorRed
        End If
      End With
    Case Else
  End Select
  'If both found, combine ID-SUSP-DI & ID-SUSP-ZJ
  If (bDI = True) And (bZJ = True) Then
    With Documents(j).Range
      .Characters.Last.FormattedText = Documents(k).Range.FormattedText
      'Close the ZJ document
      Documents(k).Close SaveChanges:=False
      'Reformat the DI document
      With .Find
        .ClearFormatting
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchWildcards = True
        .Replacement.Text = ""
        .Text = "0[=]{108}"
        .Execute Replace:=wdReplaceAll
        .Text = "[=]{108}"
        .Execute Replace:=wdReplaceAll
        .Text = " DI80440B[ ]@AGED SUSPENSE REPORT[ ]@PAGE: [0-9]{3}"
        .Execute Replace:=wdReplaceAll
        .Text = "^13[ ]@[0-9]{2}/[0-9]{2}/20[0-9]{2}"
        .Execute Replace:=wdReplaceAll
        .Text = "[ ]@CUSTOMAX (DIRECT)"
        .Execute Replace:=wdReplaceAll
        .Text = "[ ]@CUSTOMAX (JV)"
        .Execute Replace:=wdReplaceAll
        .Text = "[ ]@FUNCTION:[ ]{1,}"
        .Replacement.Text = " FUNCTION:^t"
        .Execute Replace:=wdReplaceAll
        .Text = "[ ]@FUNCTION:"
        .Execute Replace:=wdReplaceAll
        .Text = "-SERV OFFICE[ ]@0-29[ ]@30-60[ ]@61-90[ ]@91-120[ ]@121-150[ ]@151-180[ ]@180+[ ]@TOTAL"
        .Replacement.Text = "-SO^t0-29^t30-60^t61-90^t91-120^t121-150^t151-180^t180+^tTOTAL"
        .Execute Replace:=wdReplaceAll
        .Text = "[ ]{2,}"
        .Replacement.Text = "^t"
        .Execute Replace:=wdReplaceAll
        .Text = "^t[=]{2,}"
        .Execute Replace:=wdReplaceAll
        .Text = "[=]{1,}"
        .Replacement.Text = ""
        .Execute Replace:=wdReplaceAll
        .Text = "^t^13"
        .Replacement.Text = "^p"
        .Execute Replace:=wdReplaceAll
        .Text = "[^t]{2,}"
        .Replacement.Text = "^t"
        .Execute Replace:=wdReplaceAll
        .Text = "^13[0-1]^13"
        .Replacement.Text = "^p^p"
        .Execute Replace:=wdReplaceAll
      End With
      .ParagraphFormat.TabStops.ClearAll
      .DefaultTabStop = InchesToPoints(1.1)
      With .PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientLandscape
        .TopMargin = InchesToPoints(0.5)
        .BottomMargin = InchesToPoints(0.5)
        .LeftMargin = InchesToPoints(0.5)
        .RightMargin = InchesToPoints(0.5)
        .Gutter = InchesToPoints(0)
        .HeaderDistance = InchesToPoints(0.3)
        .FooterDistance = InchesToPoints(0.3)
        .PageWidth = InchesToPoints(14)
        .PageHeight = InchesToPoints(8.5)
        .FirstPageTray = wdPrinterDefaultBin
        .OtherPagesTray = wdPrinterDefaultBin
        .SectionStart = wdSectionNewPage
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .VerticalAlignment = wdAlignVerticalTop
        .SuppressEndnotes = False
        .MirrorMargins = False
      End With
      'Save the DI document as a new file.
      .SaveAs FileName:="C:\_MIS FILES\ID-SUSP-DIZJ COMBINED.docx", _
        FileFormat:=wdFormatXMLDocument, LockComments:=False, _
        SaveNativePictureFormat:=False, SaveFormsData:=False, _
        ReadOnlyRecommended:=False, AddToRecentFiles:=True, _
        EmbedTrueTypeFonts:=False, SaveAsAOCELetter:=False, _
        WritePassword:="", Password:=""
      'Close the DI document.
      '.Close SaveChanges:=False
    End With
    Exit For
  End If
Next
If (bDI = False) And (bZJ = False) Then
  MsgBox "ID-SUSP-DI and ID-SUSP-ZJ not found", vbExclamation
ElseIf bDI = False Then
  Documents("ID-SUSP-ZJ").Close SaveChanges:=False
  MsgBox "ID-SUSP-DI not found", vbExclamation
ElseIf bZJ = False Then
  Documents("ID-SUSP-DI").Close SaveChanges:=False
  MsgBox "ID-SUSP-ZJ not found", vbExclamation
End If
Application.ScreenUpdating = True
End Sub
As coded, the macro leaves the output document open, but you'll see the commented-out line for closing it.
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,323
Members
449,077
Latest member
jmsotelo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top