Share via

VBA - Call another macro

Anonymous
2017-09-06T12:47:21+00:00

Hello everyone,

I have a rather large Excel document that needs to be protected. I wish to unprotect the workbook/sheet during different stages of a macro. Rather than input the "ActiveWorkbook.Unprotect..." code I want to call another Macro which will handle all of it. This way I don't have to replicate everything over and over again.

Simple enough, however - I wish to call the Macro when a UserForm is in use or when a Module Macro is in use. Here's my coding structure:

ThisWorkbook Contains the Protect and Unprotect macros that I wish to call
UserForm1 I wish to call the Protect and Unprotect macros stored in the ThisWorkbook section.
Module1 I wish to call the Protect and Unprotect macros stored in the ThisWorkbook section.

The standard "Call UnprotectMacro" doesn't work for either of them. I also tried "Call ThisWorkbook.UnprotectMacro" and this didn't help either.

Any ideas?

Thanks,

Daniel

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Anonymous
    2017-09-06T17:53:51+00:00

    You must use:

    Application.Run "ThisWorkbook.UnprotectMacro"

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2017-09-06T13:11:51+00:00

    There is an option with the protect method when called with code which allows your code to have access to the worksheet.    In VBA help look at the UserInterfaceOnly property to the protect method.    So if you protect your sheet with code, then using this option in that command should give your code access to the worksheet and possibly you won't need to protect and unprotect the sheet in your code.  

    --

    Regards,

    Tom Ogilvy

    Was this answer helpful?

    0 comments No comments