Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 10-19-2023, 03:59 PM
Chris G Chris G is offline Macro ends after opening a file but it's not finished Windows 11 Macro ends after opening a file but it's not finished Office 2016
Novice
Macro ends after opening a file but it's not finished
 
Join Date: Oct 2023
Posts: 6
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, 2 views)
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to make users enable macro before opening the file? elaineAda Word VBA 4 02-01-2023 10:25 PM
Autorun macro when opening the file Tom cheeseburger PowerPoint 2 07-07-2021 05:42 PM
Word file says 'Opening in Protected View' but not opening. Yakbird Word 2 07-08-2019 10:55 AM
start where last session finished aymanharake Word 1 03-07-2017 03:08 PM
Macro ends after opening a file but it's not finished Prompt a macro to run when opening a specific file type gmanword Word VBA 5 11-30-2013 02:55 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:25 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft