VBAProject - Project Properties

Fire_Chief

Well-known Member
Joined
Jun 21, 2003
Messages
640
I have protected my code with a password and locked project for viewing.
I would like to be able to unlock and lock the password and viewing with VBA code.
Is this possible and what would the code be.
I have done a lot of code writing but this one is above my pay grade....


Thank You
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

zweifuss

New Member
Joined
Dec 6, 2020
Messages
29
Office Version
  1. 365
  2. 2013
Platform
  1. Windows
There is no official way. You can try SendKeys to operate the VBE menu and fill out the password dialog.
 

Fire_Chief

Well-known Member
Joined
Jun 21, 2003
Messages
640
I don't know how to use SendKeys.
What I'm trying to do Is in the opening code it will know it's my computer and unlock the project.
Any Suggestions?

Thanks for the reply
 

zweifuss

New Member
Joined
Dec 6, 2020
Messages
29
Office Version
  1. 365
  2. 2013
Platform
  1. Windows
This works for me:
VBA Code:
Public Sub HideProject()
    ' Hide project and set password to 'Pa$$w0rd'
    SendKeys "%{F11}"   ' open VBA-IDE
    VBA.DoEvents        ' wait a bit
    SendKeys "%xi"      ' menu navigation is language dependent
    SendKeys "+{Tab}{Right}{Tab}{Tab}" ' move to tab secure
    SendKeys " {Tab}{Tab}"             ' check hide checkbox with space
    SendKeys "Pa$$w0rd{Tab}"           ' fill password
    SendKeys "Pa$$w0rd{Enter}"
End Sub

 

Fire_Chief

Well-known Member
Joined
Jun 21, 2003
Messages
640

ADVERTISEMENT

Public Sub HideProject()
' Hide project and set password to 'Pa$$w0rd'
SendKeys "%{F11}" ' open VBA-IDE I stepped through the code. When I got here it opened the main page
VBA.DoEvents ' wait a bit
SendKeys "%xi" 'menu navigation is language dependent. When I executed this line it changed i SendKeys "+{Tab}{Right}{Tab}{Tab}" ' move to tab secure
SendKeys "+{Tab}{Right}{Tab}{Tab}" ' move to tab secure
SendKeys " {Tab}{Tab}" ' check hide checkbox with space
SendKeys "123{Tab}" ' fill password I used 123 as the password
SendKeys "123{Enter}"
End Sub

When I ran it fast this is what I got

Public Sub HideProject()
' Hide project and set password to 'Pa$$w0rd'
iS Pa$$w0rd Pa$$w0rd
endKeys "%{F11}" ' open VBA-IDE I stepped through the code. When I got here it opened the main page
VBA.DoEvents ' wait a bit
SendKeys "%xi" ' menu navigation is language dependent
SendKeys "+{Tab}{Right}{Tab}{Tab}" ' move to tab secure
SendKeys " {Tab}{Tab}" ' check hide checkbox with space
SendKeys "123{Tab}" ' fill password
SendKeys "123{Enter}"
End Sub

I don't understand..

Thanks
 

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
8,203
Office Version
  1. 2016
Platform
  1. Windows
Take a look here and see if it works for you :
 

Fire_Chief

Well-known Member
Joined
Jun 21, 2003
Messages
640
Thank you for this tip

Sub HintForGoodResults( )
If yourcode Is indented Then
"it is easier to for everyone to understand" AND "others are more likely to give assistance"
Else
"errors are much harder to find" OR "others dont bother"
End If
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,129,791
Messages
5,638,340
Members
417,021
Latest member
moon miner

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
Top