Run-time error '9' when renaming document

  • Good morning,


    I recorded a macro that selects and exports 3 tabs out of a document, but I then want go back to the original document and deselect the original three tabs (to prevent someone from accidentally typing info into one of the tabs and it mirroring it in the other two tabs as well). Anyway, the macro I have works great unless someone renames the original file name. I know there has to be a way around this, but I am too new to vba and literally learning as I go. I suspect the problem is in the second to last line that starts with "Windows."


    Thank you for your help!
    D


  • Re: Run-time error '9' when renaming document


    Hi djagxk8 and welcome to the forum! :)


    We can use one of the predfined names that VB has. Change this:

    Code
    Windows("RBS Audit Checklist.xlsm").Activate


    to this:

    Code
    ThisWorkbook.Activate


    Now it doesn't matter how much the workbook name changes.

    Best Regards,
    Luke M
    =======
    "A little knowledge is a dangerous thing."

  • Re: Run-time error '9' when renaming document


    <FACEPALM> I knew it would be something simple simple like that, thank you so much- it works beautifully! :)

Participate now!

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