Visual Basic Run-Time Error 1004

  • So I have a macro enabled workbook with multiple tabs. as part of the macro, it converts all the tabs to a pdf as part of a package. There is code to select the parent directory to 'print' the pdf documents to. The problem is that when you first open the template from SharePoint and save it somewhere to use, it works fine. Issue is once you've saved it somewhere and then try to move it to another folder and use it, it errors out with the 1004 error stating:

    "Document not saved. The document may be open, or an error may have been encountered when saving."

    Odd thing is I'm not trying to save the document at all, just run the print to parent directory macro. Below is the code. It gets to the line that starts with wksSheet.ExportAsFixedFormat line and this is where the error occurs. Can't seem to figure out why it works when first saved, but if the file is moved it errors out. Any ideas?

  • If you think you can get better help from Google then good luck. It's not much to ask you to follow a few simple rules to get free help.

  • It's good Forum etiquette to share solutions in case they help someone else. Our rules aren't rules just guidance how to use the Forum correctly and get the most out of it

  • No solution only that it was resolved. Once the file is saved the root directory is set and copying the file and then pasting it into a new location breaks that. Just a matter of knowing that the save location is correct when used. The file in question is a single time use file for developing PPAP submissions. Company policy prohibits us from sharing internal documents online.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!