+ Reply to Thread
Results 1 to 16 of 16

How to run a macro in password protected sheet

  1. #1
    Forum Contributor leo73pk's Avatar
    Join Date
    09-28-2006
    Location
    UAE
    MS-Off Ver
    2016, Microsoft 365
    Posts
    294

    Thumbs up How to run a macro in password protected sheet

    Description:
    I have developed a work book where in there are two sheets A & B. sheet B is linked with Sheet A i.e. values of sheet B are updated based on any change in sheet A and this is being done by a Sheet Activation Macro defined for Sheet B and every thing works perfectly.


    Problem:
    Now I have protected my MACRO (VBA code) by applying password. and I protected Sheet B as well through password. But after protecting the sheet B, MACRO is not working on activation.

    Can anyone guide me to fix this problem.
    Last edited by leo73pk; 01-06-2011 at 12:55 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: How to run a macro in password protected sheet

    The macro needs to unprotect the sheet, do its thing, and then reprotect it.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: How to run a macro in password protected sheet

    Hi,

    You would either need to unprotect and protect the sheet within your code or alternatively you could protect the worksheet using VBA setting the UserInterfaceOnly parameter to True and this allows your macros to do their stuff while protecting the sheet from user interaction.

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  4. #4
    Forum Contributor leo73pk's Avatar
    Join Date
    09-28-2006
    Location
    UAE
    MS-Off Ver
    2016, Microsoft 365
    Posts
    294

    Re: How to run a macro in password protected sheet

    Kindly let me know where to find "UserInterfaceOnly parameter" for changing its value.

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: How to run a macro in password protected sheet

    See VBE Help for Protect method

  6. #6
    Forum Contributor leo73pk's Avatar
    Join Date
    09-28-2006
    Location
    UAE
    MS-Off Ver
    2016, Microsoft 365
    Posts
    294

    Re: How to run a macro in password protected sheet

    dear SHG,

    I have seen VBA help and read the description of protect methods, ill appreciate if you could guide me from where to change the value of UserInterfaceOnly Parameter.

    Regards,

  7. #7
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: How to run a macro in password protected sheet

    You set it like this:

    Please Login or Register  to view this content.
    Note the UserInterfaceOnly setting is not saved with the workbook so would need to be re-applied each time the workbook is opened. There are also certain methods like find/replace which will not work under this setting even if run from a macro.

    Dom

  8. #8
    Forum Contributor leo73pk's Avatar
    Join Date
    09-28-2006
    Location
    UAE
    MS-Off Ver
    2016, Microsoft 365
    Posts
    294

    Re: How to run a macro in password protected sheet

    my macro is like this
    Please Login or Register  to view this content.
    I simply want to Protect my worksheet in a way that macro runs as it is running now but noone else can view this macro (VBA Code).

  9. #9
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: How to run a macro in password protected sheet

    It would be like this:

    Please Login or Register  to view this content.

    Dom

  10. #10
    Forum Contributor leo73pk's Avatar
    Join Date
    09-28-2006
    Location
    UAE
    MS-Off Ver
    2016, Microsoft 365
    Posts
    294

    Re: How to run a macro in password protected sheet

    Domski,

    That code of your is working to protect the sheet and macro is also running.
    The same thing i was doing with simple sheet protection and but i simply want that no one can view the VBA code if we right click the sheet & view code tab. how to do so.

    Hope this gives you understanding what actually i'm looking forward.

    Regards,

  11. #11
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: How to run a macro in password protected sheet

    Have you password protected your VBA project? In the VBA editor right click on the project in the project explorer and select VBAProject Properties and then set the password on the Protection tab.

    Dom

  12. #12
    Forum Contributor leo73pk's Avatar
    Join Date
    09-28-2006
    Location
    UAE
    MS-Off Ver
    2016, Microsoft 365
    Posts
    294

    Re: How to run a macro in password protected sheet

    Hi Dom,

    Thanks for your guidance, the macro you suggest followed by procedure to hide VBA code is working i'm testing it thru different angles. One think i have witnessed that you have deleted following row from my vba code

    Please Login or Register  to view this content.
    does it have any impact on the functionality of the macro.

    Regards,

  13. #13
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: How to run a macro in password protected sheet

    That line of code is basically saying ignore any errors that you encounter. In my opinion would be better to use a proper error handler than just blast through although there obviously are occasions when it can be used effectively.

    Something like this:

    Please Login or Register  to view this content.

    Dom

  14. #14
    Forum Contributor leo73pk's Avatar
    Join Date
    09-28-2006
    Location
    UAE
    MS-Off Ver
    2016, Microsoft 365
    Posts
    294

    Re: How to run a macro in password protected sheet

    Dear Dom,


    Thanks for your help. Now the changes you proposed gives me desired results. I appreciate your patience hearing and guidance. If you accept may i add you as friend i'm sending you friend invitation.

    Regards,

  15. #15
    Registered User
    Join Date
    06-14-2013
    Location
    Mumbai
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: How to run a macro in password protected sheet

    Dear Dom, leo73pk

    It seems my problem is same as urs.

    So kindly help.
    I want to run a procedure to update the current market prices in ONE Sheet. Also I want to hide this sheet and then protect the complete workbook.

    CODE IS :

    Please Login or Register  to view this content.

    Regards
    Anchal
    Last edited by arlu1201; 06-14-2013 at 05:32 AM.

  16. #16
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: How to run a macro in password protected sheet

    Anchal,

    Welcome to the forum.

    2 pointers-

    I have added code tags to your post. As per forum rule 3, you need to use them whenever you put any code in your post. Please add them in future. In order to put code tags, either type [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] at the end of it, OR you can highlight your code and click the # icon at the top of your post window.

    Also,

    Unfortunately you need to post your question in a new thread, it's against the forum rules to post a question in the thread of another user. If you create your own thread, any advice will be tailored to your situation so you should include a description of what you've done and are trying to do. Also, if you feel that this thread is particularly relevant to what you are trying to do, you can surely include a link to it in your new thread.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1