View Single Post
 
Old 10-19-2023, 03:59 PM
Chris G Chris G is offline Windows 11 Office 2016
Novice
 
Join Date: Oct 2023
Posts: 2
Chris G is on a distinguished road
Default Macro ends after opening a file but it's not finished

I have a macro, call it A, that calls a second macro, call it B, whose job is to open a file of standardized text, copy its contents, close the file, and paste them into paragraph 3 of the active document (and do some other processing).

This has been working fine for ages. But now it doesn't. Everything stops when B macro opens the file. There is no sign of error, and if I put a message box on the line under the command to open the file, it fails to display. Even if I step through the code, it just stops, no yellow highlight line appears beneath the line of code that opens the file.

First part of macro B here:

Code:
    Dim docCurrent As Document ' variable for the currently open file
    Dim docBraillePrelim As Document ' variable for the document where we are lifting content from
    Dim rngCurrent As Range ' variable for content of our current working file
    Dim rngPub As Range
    Dim rngBraillePrelim As Range  ' variable for content of source file
    Dim strBraillePrelimName As String ' Variable for name of file to open
    
    ' auto-update year mentioned in Braille prelims
    
    Dim rngOrg As Range
    Dim rngOrgName As Range
    Dim dtYear As Date
    Dim strDateYear As String
        strDateYear = CStr(Format(Now, "yyyy"))
    Dim strYear As String
        strYear = "[year]"

    
    strBraillePrelimName = "G:\Accessible Format Transcription\AUTOMATION TOOLKIT\TOOLKIT FILES\PRELIM TEXT\BRAILLE PRELIMS TEXT.docx"
    
    On Error GoTo ErrorHandling
    
    ' Open Braille Prelims doc and define range of its contents

    Set rngCurrent = ActiveDocument.Paragraphs(3).Range.FormattedText ' define target range of insertion of the text
                    
    Debug.Print rngCurrent
    
    Set docBraillePrelim = Documents.Open(fileName:=strBraillePrelimName)
    Set rngBraillePrelim = docBraillePrelim.Range ' This is the range content of the Braille prelims

etc etc
Even more oddly, I have a second macro which performs the same function but with different files, and it still works fine.

Would appreciate any clues as to what might be going wrong, or another way to do the same thing. As I said, the macro stops all activity at Documents.Open, which it successfully does, but there's a lot more to go;
Attached Files
File Type: txt PrelimsInsertBraille.txt (5.4 KB, 0 views)
Reply With Quote