Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #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: 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
  #2  
Old 10-19-2023, 11:42 PM
Guessed's Avatar
Guessed Guessed is offline Macro ends after opening a file but it's not finished Windows 10 Macro ends after opening a file but it's not finished Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Is there a template containing macros attached to the 'BRAILLE PRELIMS TEXT.docx' document?

If you are importing the entire contents of that document into the activedocument then it might be simpler to import the text from that file.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 10-23-2023, 01:34 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: 2
Chris G is on a distinguished road
Default

Thanks for your response.

There weren't macros attached to the document template, but I did change the template back to Normal.dotm from one of my custom templates, and the offending macro now runs through to completion.

No idea just what caused the issue, but happy it's back running.
Reply With Quote
  #4  
Old 10-24-2023, 01:07 AM
Italophile Italophile 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 2021
Expert
 
Join Date: Mar 2022
Posts: 338
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

Quote:
Originally Posted by Chris G View Post
Thanks for your response.

There weren't macros attached to the document template, but I did change the template back to Normal.dotm from one of my custom templates, and the offending macro now runs through to completion.

No idea just what caused the issue, but happy it's back running.
It's a bit soon to be happy. If changing the attached template solves the issue it suggests that Word wasn't happy with that template. It may be corrupt.
Reply With Quote
Reply



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 03:24 PM.


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