Code to unprotect VBAproject

BX

Board Regular
Joined
Jun 2, 2002
Messages
172
Hi
I have protected my project to hide the code from users. However, in one of the macros I use prior to sending the file, I delete extra sheets and user forms. Since the project is protect the code results in an error.
At the start of the code is there away to unprotect my project and then at the end reprotect the project.

something like: project ("name").unprotect "1234"
obviously not right, but what is the proper way to refer to a project and unprotect and re-protect it.

Thanks,
BX
 
pretty boring here in fly-over country as well...TGIF
 
Upvote 0

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
kskinne said:
good point Tom, I never even thought of sendkeys - but I still wouldn't put code like that into a workbook that I was going to distribute. otherwise what would be the point of protecting the project? unless you were going to change the "Password" part of the code to an inputbox - yes, you still have to enter a password when prompted, but it would still be easier than having to open the VBE.

kevin

Yes, neither would I. Plus you need to be aware that Opening up a protected project leaves it open until you close it again.
So what would it be useful for ?? changing /importing/exporting new Modules for updating (That you do and NOT the OP)
 
Upvote 0
Hi Tom.. !!!!!!!
I am a big fan of you, Your book Excel VBA 24 hours Trainer is so fantastic, I am new to this forum but i am very glad to see you..
I have just made a very minute change on your main code, so that the position check can be skipped.

Thanks a lot for your book.. !! Its very helpful..

Code:
Sub TestUnprotectProject()
    Dim Wb As Workbook
    Application.EnableEvents = False
    Application.DisplayAlerts = False
    Set Wb = Workbooks.Open("C:\Users\delip\Desktop\WorkbookToUnprotect.xlsx") 'Change the file name to open
        
        Do Until Application.Ready = True
        
        Loop
        
        With Application
            'Go to the VBE
            .SendKeys "%{F11}", True
            'Activate Project Explorer window
            .SendKeys "^r", True
            'Used down-arrow to request password .SendKeys "{DOWN}", True
            .SendKeys "{DOWN}", True
            'Enter your password - - this example is "Password"
            .SendKeys "Password"
            'Enter again
            .SendKeys "~", True
        End With
        
    Application.EnableEvents = False
    Application.DisplayAlerts = False
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,126
Messages
6,129,007
Members
449,480
Latest member
yesitisasport

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top