Consulting

Results 1 to 8 of 8

Thread: VBA crashing on 'Documents.Add'

  1. #1

    VBA crashing on 'Documents.Add'

    When my code executes and encounters Documents.Add, Word shuts down. I cannot even capture the error.

    Why would this happen? What should I be looking for? Not happening on all of my computers. 5 process this line normally. 2 crash repeatedly.

    It happens regardless of whether I assign a template (Documents.add template:="c:\path\template.doc" or just Documents.add)

    Driving me crazy.

    Roy

  2. #2
    Reboot the PC and try again. Word has a bad habit of storing up minor VBA errors and eventually it will crash with nonsensical errors. Rebooting will clear it.
    This is a particular problem on laptops which tend not to be rebooted frequently.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    Thanks, Graham, but did that first, and often.

    Plus I can consistently repeat this on two (so far) different machines at any time. (Actually, on one machine, Word crashes and the restarts, as described in the initial post. On the other machine, Word actually adds the new document but then totally jumps out of the module. It won't process any lines that follow. The steps beneath the 'Documents.Add' line are not processed; neither are any subsequent lines in the 'parent' module that calls the 'Documents.Add' containing module processed. I cannot capture anything with an error handler (for the reasons stated in the previous sentence).

    It is insane, but very real and readily duplicable. Even a module as simple as the single line 'Documents.Add' will behave consistently as described, but (so far) only on these 2 machines. (Does Microsoft follow these boards?)

    Roy

  4. #4
    This forum is independent from Microsoft.

    This is not a normal error. A macro that creates a new document e.g.

    Sub Macro1
    Documents.Add
    End Sub
    Should not cause a crash in any Word version. The fact that it does suggests a local issue.
    Repair Office and then before starting Word again see http://www.gmayor.com/what_to_do_when_word_crashes.htm
    Rename the normal template to (say) Normal.old and then try again.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  5. #5
    We had done that as well (both Repair -- and both kinds of repairs -- and recreating normal.dotm). Same issue. Is it helpful to know that Ctrl-N works (i.e., it doesn't crash Word)? Of course, it's not a macro, but it performs the same function as Documents.Add.

    I had not tried the long list of other clean-ups proposed in your link. I will try those today. Thanks.

  6. #6
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    I have a DOT with Rob Bovey's Code Cleaner for Word (circa 2001), but it's based on his original Excel Code Cleaner, which has been converted to a COM add in.

    The Word code clean doesn't seem to be maintained after 16 years

    http://www.appspro.com/Utilities/CodeCleaner.htm

    During the process of creating VBA programs a lot of junk code builds up in your files. If you don't clean your files periodically you will begin to experience strange problems caused by this extra baggage. Cleaning a project involves exporting the contents of all its VBComponents to text files, deleting the components and then importing the components back from the text files.
    However, the issue and the fix are still the same, and you might give it a try

    It's fixed a 'Why did it do that????' macro issue in Excel many times, and occasionally in Word

    It's a mite tedious to do the Exports / Imports manually, but you could try to export each module (as pure text), delete the modules (standard, userform, class, document) from the document, and then import the text files.
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  7. #7
    Just got an email from a 'distant user' who reports: "I've had a recentproblem with my computer which is causing my computer to crash when I use your program. About aweek ago, the computer shut down unexpectedly while I was in the middle ofworking (I suspect it was one of those updates that get installed withoutnotice). After I rebooted, I noticed problems with Word, as my Normaltemplate (which I had modified to include additional styles, plus a few macros)had disappeared and had been replaced by the plain one that comes withWord. When ever I use a tool that creates or adds a new document, Word crashes . . . ."

    The problem I described in my first letter is now acting in the same fashion on 3 of 9 computers, and seems to be occurring in direct response to an upgrade of Word (I checked that out with the other two users). Is this something I should report to Microsoft? What's the best board for that?

  8. #8
    On more helpful(?) update. I programmed a SendKeys "^n" in place of Documents.Add and it works fine. There is a 'speed' issue and I found I needed to add a 'Sleep' command, but at least I have a workaround. But why would one work and not the other?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •