none
error 75 with activedocument.close RRS feed

  • Question

  • Hello.  I have converted a vba module from Word 2003 .dot to word 2010 .dotm.  This program loops through all templates in the specified directories and dumps the vba code into a text file.  It works fine in 2003, but fails with error 75 - File/Path error- in 2010.  Here is the code.

     For i = 1 To intFileCnt - 1
      strFullName = varFileNames(i)
      strCode = ""
      Set doc = Documents.Open(strFullName)
      strDoc = "****************************  " & doc & "  ******************************"
      Write #1,
      Write #1, strDoc
      Write #1,
      
      
      For Each vbc In doc.VBProject.VBComponents
       Set mdl = vbc.CodeModule
       If mdl.CountOfLines > 0 Then
        strmdl = "#########################  " & _
        "Module " & Left(varFileNames(i), Len(varFileNames(i)) - 4) & _
        "." & mdl & "  #################################"
       Write #1,
       Write #1, strmdl
       Write #1,
       strCode = vbCrLf & vbCrLf & _
            "[" & vbc.Name & "]" & vbCrLf & _
            mdl.Lines(1, mdl.CountOfLines)
       Write #1, strCode
       
      '  vbc.Export Left(strFullName, Len(strFullName) - 4) & _
            "." & vbc.Name & _
            ".modulecode.txt"
       End If
      Next
      On Error Resume Next
      doc.Close
      On Error GoTo 0
    '  Set doc = Nothing
     Next i
    


    The failure is at the bottom, 'doc.close'.  I have tried many variations with no success.  At the point of execution, the active document is the last template to be dumped to the text file.  The program closes it and grabs the next one.  

    I am also using Windows 7.  Maybe this is a rights thing, but I have given myself and 'everyone' full access'.

     

    Thanks for considering my problem.

    Ken

     

    Friday, August 19, 2011 9:44 PM

Answers

  • Hi Ken

    <<Is there a way to get further details on the error? >>

    Not that I know of. I can't recall having ever encountered this error, before, and the circumstances are a bit puzzling, to say the least.

    In your shoes, there are a number of things I'd try:

    1. Be sure to set the Application.AutomationSecurity to explicitly DISABLE macros. Perhaps there's a macro in the template that's firing (AutoOpen or AutoClose, for example) that's triggering the problem

    2. make sure you don't have any add-ins loaded that might have an event running or a FileClose macro that could be triggering. Also check your Normal.dotm for something like this.

    3. Comment out Doc.Close, enable Set doc = Nothing, put a break point immediately after that, switch to the Word window with the opened template file and try closing it manually (as the end-user). Do you get an error under those circumstances? Or some kind of message?

    4. In 2007/2010 it's difficult phrase this question, and difficult to formulate the answer, but... What are your security settings in the Trust Center? For Macro? For Trusted Locations?

    5. None of these templates happpen to be linked to a VSTO solution, by any chance?


    Cindy Meister, VSTO/Word MVP
    Monday, August 22, 2011 4:24 PM
    Moderator

All replies

  • Since you're not modifying the document, you could try

     

    doc.Close SaveChanges:=False
    


    Regards, Hans Vogelaar
    Friday, August 19, 2011 11:03 PM
  • Thank you for your reply Hans.  

    I think I have tried all of the SaveChanges options: including False, wdDoNotSaveChanges, wdPromptToSaveChanges. The same error persists. 

    Ken

     

    Friday, August 19, 2011 11:07 PM
  • I'm using Word 2010 on Windows 7.

    I copied your code into a macro, and added a few lines to fill the array with filenames and to open a text file for output. The macro ran without a hitch and produced a text file with the code from the modules in the listed documents, as intended.

    So the problem doesn't seem to be with Word 2010 or Windows 7 per se. I don't understand why you'd get an error on the line that closes the document...


    Regards, Hans Vogelaar
    Friday, August 19, 2011 11:29 PM
  • Hello,

    Please check if "Trust access to the VBA project object model" is checked in the Trust Center. Do you have several Word versions on your PC?


    Regards from Belarus (GMT + 2),

    Andrei Smolin
    Add-in Express Team Leader
    Saturday, August 20, 2011 6:31 AM
  • Hi Ken

    I'm a bit curious about your use of Write #1. You don't show us where you instantiate/open that, nor where you close it. My thought is that the error is due to not managing this (log?) file correctly before closing the document that's running the code?


    Cindy Meister, VSTO/Word MVP
    Saturday, August 20, 2011 11:32 AM
    Moderator
  • Thanks fo r the reply Andrei.  I do have  I do have "Trust access to the VBA project object model" checked, and office 2010 is the only version of Word on this PC.  I loaded this PC only with Win 7 and Office 2010 as a model for our future changeover to the new OS/software. Thanks fo r the reply Andrei.

    Ken

    Monday, August 22, 2011 3:07 PM
  • Thanks Cindy.  The file handle #1 is closed in the very next line following the 'Next i' in the code I included.  I did not include the code that instantiates and decides which code the user wants to output to the text file, or anything following the loop that contains the error.  Also, I am not closing the document that is running the code, I am closing a .dot that was opened by the module running the code.

    Here are a couple of bits that may shed light for you or anyone else:

    If I 'set doc = Nothing'  The program moves on perfectly fine, opening the next .dot and processing.  Just leaves me with all the old items open.

    The program works fine with Office 2003 on XP.

     

    Thanks

    Ken

     

    Monday, August 22, 2011 3:18 PM
  • Hi Ken

    <<If I 'set doc = Nothing'  The program moves on perfectly fine, opening the next .dot and processing.  Just leaves me with all the old items open.>>

    I take it that settind doc = Nothing immediately after closing doesn't help...

    I'm always suspicious of On Error Resume Next - that tends to cloak problems. Is that there so that you won't see this error any more? Or are you getting the error despite having this activated for the one call? If the latter, comment those two lines out and tell us what errors you get, then?

    You say these are *.dot files - so not *.dotm? And they obviously contain macros...

    Are they in a network location or on the local drive? There have been issues with Office 2010 and templates located on network drives, due to security settings - although not this problem. But perhaps there is a relationship...


    Cindy Meister, VSTO/Word MVP
    Monday, August 22, 2011 3:48 PM
    Moderator
  • Sorry, they are .dotm files.  I converted them all from 2003 .dot's.

    The 'On Error Resume Next' was just a try to get past the error and continue.  It does not work.  The error stops program processing, and once the error is triggered I cannot skip to the next line and continue.

    These templates are on the local drive.

    Is there a way to get further details on the error?  I checked the PC event log and was not able to find anything.

    I thought the problem may lie with closing the active document, but when I changed active to the template that was running the code and then tried to close the named document I got the same error.

     

    I really appreciate the help here.

    Ken

     

    Monday, August 22, 2011 4:04 PM
  • Hi Ken

    <<Is there a way to get further details on the error? >>

    Not that I know of. I can't recall having ever encountered this error, before, and the circumstances are a bit puzzling, to say the least.

    In your shoes, there are a number of things I'd try:

    1. Be sure to set the Application.AutomationSecurity to explicitly DISABLE macros. Perhaps there's a macro in the template that's firing (AutoOpen or AutoClose, for example) that's triggering the problem

    2. make sure you don't have any add-ins loaded that might have an event running or a FileClose macro that could be triggering. Also check your Normal.dotm for something like this.

    3. Comment out Doc.Close, enable Set doc = Nothing, put a break point immediately after that, switch to the Word window with the opened template file and try closing it manually (as the end-user). Do you get an error under those circumstances? Or some kind of message?

    4. In 2007/2010 it's difficult phrase this question, and difficult to formulate the answer, but... What are your security settings in the Trust Center? For Macro? For Trusted Locations?

    5. None of these templates happpen to be linked to a VSTO solution, by any chance?


    Cindy Meister, VSTO/Word MVP
    Monday, August 22, 2011 4:24 PM
    Moderator
  • I think you are right about macros running in the templates I am trying to read.  Many of these are located in the startup folder and have references to other templates.

     Does 2010 deal with them differently?  I did disable app.automationsecurity, but when I did, program execution stopped as soon as the 'Set doc = Documents.Open(strFullName)' line ran. vba editor switched over to the newly opened template.

    Is there a way to open a doc (.dotm) in a similar fashion as using the /m command when starting Word?

    Ken


    Tuesday, August 23, 2011 5:24 PM
  • Hi Ken

    The problem is almost certainly that you're working with templates that are currently loaded as Add-ins (because they're in the Startup folder). Even if you set AutomationSecurtity to msoAutomationSecurityForceDisable any "Auto" macros are going to execute because the code is already loaded.

    You'd first need to loop the Application.Addins collection and unload all of these before you open them with your code.


    Cindy Meister, VSTO/Word MVP
    Wednesday, August 24, 2011 6:50 AM
    Moderator