I want to restrict my macro to a specific worksheet.

  • The macros I suggested don't contain any code which opens a file so it shouldn't be opening anything. Are you using the code as I wrote it or did you modify it in any way? If you modified it, please post the modified code.

    You can say "THANK YOU" for help received by clicking the "Like" icon in the bottom right corner of the helper's post.
    Practice makes perfect. I am very far from perfect so I'm still practising.

  • The workbook that I uploaded copies the data from Reports Data Collect, the Undo macro clears the report. If you run the macros they work fine without prompting to save or open any workbooks.

  • I ran the macros on the file you posted and the macros worked properly. I then saved the file with a new name, closed it and re-opened it, and it also worked properly so I'm not sure why they are not working for you. Did you try copy/pasting the code into the new file?

    You can say "THANK YOU" for help received by clicking the "Like" icon in the bottom right corner of the helper's post.
    Practice makes perfect. I am very far from perfect so I'm still practising.

  • So I figured out the issue. I have customized my ribbon with Macro buttons. Neither of you would have known that. If I use those buttons, then Excel wants to open my original file. If I just run the macro from View Macros, it works fine. I had assumed that once I C&P the code, the macro buttons would be associated with the new code. Apparently, that doesn't happen, or there is a step I must take to associate the button with the new code. Anyway, I recreated my buttons and everything works great.


    Thank you both for all your help. I greatly appreciate your patience!


    As an aside, I've started the VBA tutorials provided on this site...I hope it doesn't teach me just enough to be dangerous!


    Thanks again!

  • Glad we could help and that it all worked out. Roy hit the nail on the head!!! :)

    You can say "THANK YOU" for help received by clicking the "Like" icon in the bottom right corner of the helper's post.
    Practice makes perfect. I am very far from perfect so I'm still practising.

  • I take it you are customising the Ribbon in Excel Options. I'm not exactly sure how that works because I've never used it. I generally use the xml to do it.


    Good luck with the courses, post back with specific questions and I'm sure we can help.

Participate now!

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