Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
dd dd is offline
external usenet poster
 
Posts: 95
Default One more question on worksheet protection

Is there a way to enable/disable the VBA password and lock project for
viewing, using a macro?

Dylan


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 329
Default One more question on worksheet protection

Hi Dylan,

Assuming you know the password, the following code, based on work by fellow
MVP Bill Manville, will unprotect/protect a vba project:

Sub UnprotectVBProj(ByVal Pwd As String)
Dim vbProj As Object
Set vbProj = ThisWorkbook.VBProject
If vbProj.Protection < 1 Then Exit Sub ' already unprotected
Set Application.VBE.ActiveVBProject = vbProj
SendKeys Pwd & "~~"
Application.VBE.CommandBars(1).FindControl(ID:=257 8, recursive:=True).Execute
End Sub

Sub ProtectVBProj(ByVal Pwd As String)
Dim vbProj As Object
Set vbProj = ThisWorkbook.VBProject
If vbProj.Protection = 1 Then Exit Sub ' already protected
Set Application.VBE.ActiveVBProject = vbProj
SendKeys "+{TAB}{RIGHT}%V{+}{TAB}" & Pwd & "{TAB}" & Pwd & "~"
Application.VBE.CommandBars(1).FindControl(ID:=257 8, recursive:=True).Execute
End Sub

Cheers

--
macropod
[MVP - Microsoft Word]


"dd" <dd.dd wrote in message ...
| Is there a way to enable/disable the VBA password and lock project for
| viewing, using a macro?
|
| Dylan
|
|


  #3   Report Post  
Posted to microsoft.public.excel.programming
dd dd is offline
external usenet poster
 
Posts: 95
Default One more question on worksheet protection

Hi macropod

macropod, your original version probably works fine, but due to my lack of
knowledge, I don't know how to run it !!

I want to assign it to a custom menu button, but can't see the macro in the
list of available macros.

If I remove the (ByVal Pwd As String), add Dim Pwd As String, and change
Sendkeys to include the confirm password. When I now run it, the Dialog box
remains on the screen.

How do I use the original code?
How do I okay the dialog?

Sub ProtectVBProj() ' to allow it to appear as a macro
'Sub protectVBProj(ByVal Pwd As String) 'not sure how to call this as a
macro?
Dim Pwd As String
Dim vbProj As Object
Set vbProj = ThisWorkbook.VBProject
If vbProj.Protection = 1 Then Exit Sub ' already protected
Set Application.VBE.ActiveVBProject = vbProj
SendKeys "+{TAB}{RIGHT}%V{+}{TAB}" & Pwd & "12345" & "{TAB}" & Pwd & "12345"
'However, the dialog remains on the screen - how do I update it.
Application.VBE.CommandBars(1).FindControl(ID:=257 8,
recursive:=True).Execute
End Sub


"macropod" wrote in message
...
Hi Dylan,

Assuming you know the password, the following code, based on work by fellow
MVP Bill Manville, will unprotect/protect a vba project:

Sub UnprotectVBProj(ByVal Pwd As String)
Dim vbProj As Object
Set vbProj = ThisWorkbook.VBProject
If vbProj.Protection < 1 Then Exit Sub ' already unprotected
Set Application.VBE.ActiveVBProject = vbProj
SendKeys Pwd & "~~"
Application.VBE.CommandBars(1).FindControl(ID:=257 8,
recursive:=True).Execute
End Sub

Sub ProtectVBProj(ByVal Pwd As String)
Dim vbProj As Object
Set vbProj = ThisWorkbook.VBProject
If vbProj.Protection = 1 Then Exit Sub ' already protected
Set Application.VBE.ActiveVBProject = vbProj
SendKeys "+{TAB}{RIGHT}%V{+}{TAB}" & Pwd & "{TAB}" & Pwd & "~"
Application.VBE.CommandBars(1).FindControl(ID:=257 8,
recursive:=True).Execute
End Sub

Cheers

--
macropod
[MVP - Microsoft Word]


"dd" <dd.dd wrote in message ...
| Is there a way to enable/disable the VBA password and lock project for
| viewing, using a macro?
|
| Dylan
|
|



  #4   Report Post  
Posted to microsoft.public.excel.programming
dd dd is offline
external usenet poster
 
Posts: 95
Default One more question on worksheet protection

macropod,

Thanks very much for providing this macro and answering my question.

I managed to figure out that: & "{Enter}" will close the dialogs. I now find
that the macro runs on the workbook where it is saved (personal macros
workbook, which is hidden) rather than the workbook I'm working on.

Is there any way to apply it to all open workbooks, or, maybe to select from
a list of workbooks?

Regards
Dylan

"dd" <dd.dd wrote in message ...
Hi macropod

macropod, your original version probably works fine, but due to my lack of
knowledge, I don't know how to run it !!

I want to assign it to a custom menu button, but can't see the macro in the
list of available macros.

If I remove the (ByVal Pwd As String), add Dim Pwd As String, and change
Sendkeys to include the confirm password. When I now run it, the Dialog box
remains on the screen.

How do I use the original code?
How do I okay the dialog?

Sub ProtectVBProj() ' to allow it to appear as a macro
'Sub protectVBProj(ByVal Pwd As String) 'not sure how to call this as a
macro?
Dim Pwd As String
Dim vbProj As Object
Set vbProj = ThisWorkbook.VBProject
If vbProj.Protection = 1 Then Exit Sub ' already protected
Set Application.VBE.ActiveVBProject = vbProj
SendKeys "+{TAB}{RIGHT}%V{+}{TAB}" & Pwd & "12345" & "{TAB}" & Pwd & "12345"
'However, the dialog remains on the screen - how do I update it.
Application.VBE.CommandBars(1).FindControl(ID:=257 8,
recursive:=True).Execute
End Sub


"macropod" wrote in message
...
Hi Dylan,

Assuming you know the password, the following code, based on work by fellow
MVP Bill Manville, will unprotect/protect a vba project:

Sub UnprotectVBProj(ByVal Pwd As String)
Dim vbProj As Object
Set vbProj = ThisWorkbook.VBProject
If vbProj.Protection < 1 Then Exit Sub ' already unprotected
Set Application.VBE.ActiveVBProject = vbProj
SendKeys Pwd & "~~"
Application.VBE.CommandBars(1).FindControl(ID:=257 8,
recursive:=True).Execute
End Sub

Sub ProtectVBProj(ByVal Pwd As String)
Dim vbProj As Object
Set vbProj = ThisWorkbook.VBProject
If vbProj.Protection = 1 Then Exit Sub ' already protected
Set Application.VBE.ActiveVBProject = vbProj
SendKeys "+{TAB}{RIGHT}%V{+}{TAB}" & Pwd & "{TAB}" & Pwd & "~"
Application.VBE.CommandBars(1).FindControl(ID:=257 8,
recursive:=True).Execute
End Sub

Cheers

--
macropod
[MVP - Microsoft Word]


"dd" <dd.dd wrote in message ...
| Is there a way to enable/disable the VBA password and lock project for
| viewing, using a macro?
|
| Dylan
|
|




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 329
Default One more question on worksheet protection

Hi Dylan,

To do run the code against a different workbook, or a set of workbooks, you'd
add an additional argument to the code, as follows, then call the routines
with both the workbook names and passwords.

Sub UnprotectVBProject(WkBk As Workbook, ByVal Pwd As String)
Dim vbProj As Object
Set vbProj = WkBk.VBProject
If vbProj.Protection < 1 Then Exit Sub ' already unprotected
Set Application.VBE.ActiveVBProject = vbProj
SendKeys Pwd & "~~"
Application.VBE.CommandBars(1).FindControl(ID:=257 8, recursive:=True).Execute
End Sub

Sub ProtectVBProject(WkBk As Workbook, ByVal Pwd As String)
Dim vbProj As Object
Set vbProj = WkBk.VBProject
If vbProj.Protection = 1 Then Exit Sub ' already protected
Set Application.VBE.ActiveVBProject = vbProj
SendKeys "+{TAB}{RIGHT}%V{+}{TAB}" & Pwd & "{TAB}" & Pwd & "~"
Application.VBE.CommandBars(1).FindControl(ID:=257 8, recursive:=True).Execute
End Sub

Cheers

--
macropod
[MVP - Microsoft Word]


"dd" <dd.dd wrote in message ...
| macropod,
|
| Thanks very much for providing this macro and answering my question.
|
| I managed to figure out that: & "{Enter}" will close the dialogs. I now find
| that the macro runs on the workbook where it is saved (personal macros
| workbook, which is hidden) rather than the workbook I'm working on.
|
| Is there any way to apply it to all open workbooks, or, maybe to select from
| a list of workbooks?
|
| Regards
| Dylan
|
| "dd" <dd.dd wrote in message ...
| Hi macropod
|
| macropod, your original version probably works fine, but due to my lack of
| knowledge, I don't know how to run it !!
|
| I want to assign it to a custom menu button, but can't see the macro in the
| list of available macros.
|
| If I remove the (ByVal Pwd As String), add Dim Pwd As String, and change
| Sendkeys to include the confirm password. When I now run it, the Dialog box
| remains on the screen.
|
| How do I use the original code?
| How do I okay the dialog?
|
| Sub ProtectVBProj() ' to allow it to appear as a macro
| 'Sub protectVBProj(ByVal Pwd As String) 'not sure how to call this as a
| macro?
| Dim Pwd As String
| Dim vbProj As Object
| Set vbProj = ThisWorkbook.VBProject
| If vbProj.Protection = 1 Then Exit Sub ' already protected
| Set Application.VBE.ActiveVBProject = vbProj
| SendKeys "+{TAB}{RIGHT}%V{+}{TAB}" & Pwd & "12345" & "{TAB}" & Pwd & "12345"
| 'However, the dialog remains on the screen - how do I update it.
| Application.VBE.CommandBars(1).FindControl(ID:=257 8,
| recursive:=True).Execute
| End Sub
|
|
| "macropod" wrote in message
| ...
| Hi Dylan,
|
| Assuming you know the password, the following code, based on work by fellow
| MVP Bill Manville, will unprotect/protect a vba project:
|
| Sub UnprotectVBProj(ByVal Pwd As String)
| Dim vbProj As Object
| Set vbProj = ThisWorkbook.VBProject
| If vbProj.Protection < 1 Then Exit Sub ' already unprotected
| Set Application.VBE.ActiveVBProject = vbProj
| SendKeys Pwd & "~~"
| Application.VBE.CommandBars(1).FindControl(ID:=257 8,
| recursive:=True).Execute
| End Sub
|
| Sub ProtectVBProj(ByVal Pwd As String)
| Dim vbProj As Object
| Set vbProj = ThisWorkbook.VBProject
| If vbProj.Protection = 1 Then Exit Sub ' already protected
| Set Application.VBE.ActiveVBProject = vbProj
| SendKeys "+{TAB}{RIGHT}%V{+}{TAB}" & Pwd & "{TAB}" & Pwd & "~"
| Application.VBE.CommandBars(1).FindControl(ID:=257 8,
| recursive:=True).Execute
| End Sub
|
| Cheers
|
| --
| macropod
| [MVP - Microsoft Word]
|
|
| "dd" <dd.dd wrote in message ...
| | Is there a way to enable/disable the VBA password and lock project for
| | viewing, using a macro?
| |
| | Dylan
| |
| |
|
|
|
|




  #6   Report Post  
Posted to microsoft.public.excel.programming
dd dd is offline
external usenet poster
 
Posts: 95
Default One more question on worksheet protection

Hi Macropod,

I still can't see it in my macros list.

Can you give me an example of how to call it?

Much obliged
Dylan

"macropod" wrote in message
...
Hi Dylan,

To do run the code against a different workbook, or a set of workbooks,
you'd
add an additional argument to the code, as follows, then call the routines
with both the workbook names and passwords.

Sub UnprotectVBProject(WkBk As Workbook, ByVal Pwd As String)
Dim vbProj As Object
Set vbProj = WkBk.VBProject
If vbProj.Protection < 1 Then Exit Sub ' already unprotected
Set Application.VBE.ActiveVBProject = vbProj
SendKeys Pwd & "~~"
Application.VBE.CommandBars(1).FindControl(ID:=257 8,
recursive:=True).Execute
End Sub

Sub ProtectVBProject(WkBk As Workbook, ByVal Pwd As String)
Dim vbProj As Object
Set vbProj = WkBk.VBProject
If vbProj.Protection = 1 Then Exit Sub ' already protected
Set Application.VBE.ActiveVBProject = vbProj
SendKeys "+{TAB}{RIGHT}%V{+}{TAB}" & Pwd & "{TAB}" & Pwd & "~"
Application.VBE.CommandBars(1).FindControl(ID:=257 8,
recursive:=True).Execute
End Sub

Cheers

--
macropod
[MVP - Microsoft Word]


"dd" <dd.dd wrote in message ...
| macropod,
|
| Thanks very much for providing this macro and answering my question.
|
| I managed to figure out that: & "{Enter}" will close the dialogs. I now
find
| that the macro runs on the workbook where it is saved (personal macros
| workbook, which is hidden) rather than the workbook I'm working on.
|
| Is there any way to apply it to all open workbooks, or, maybe to select
from
| a list of workbooks?
|
| Regards
| Dylan
|
| "dd" <dd.dd wrote in message
...
| Hi macropod
|
| macropod, your original version probably works fine, but due to my lack of
| knowledge, I don't know how to run it !!
|
| I want to assign it to a custom menu button, but can't see the macro in
the
| list of available macros.
|
| If I remove the (ByVal Pwd As String), add Dim Pwd As String, and change
| Sendkeys to include the confirm password. When I now run it, the Dialog
box
| remains on the screen.
|
| How do I use the original code?
| How do I okay the dialog?
|
| Sub ProtectVBProj() ' to allow it to appear as a macro
| 'Sub protectVBProj(ByVal Pwd As String) 'not sure how to call this as a
| macro?
| Dim Pwd As String
| Dim vbProj As Object
| Set vbProj = ThisWorkbook.VBProject
| If vbProj.Protection = 1 Then Exit Sub ' already protected
| Set Application.VBE.ActiveVBProject = vbProj
| SendKeys "+{TAB}{RIGHT}%V{+}{TAB}" & Pwd & "12345" & "{TAB}" & Pwd &
"12345"
| 'However, the dialog remains on the screen - how do I update it.
| Application.VBE.CommandBars(1).FindControl(ID:=257 8,
| recursive:=True).Execute
| End Sub
|
|
| "macropod" wrote in message
| ...
| Hi Dylan,
|
| Assuming you know the password, the following code, based on work by
fellow
| MVP Bill Manville, will unprotect/protect a vba project:
|
| Sub UnprotectVBProj(ByVal Pwd As String)
| Dim vbProj As Object
| Set vbProj = ThisWorkbook.VBProject
| If vbProj.Protection < 1 Then Exit Sub ' already unprotected
| Set Application.VBE.ActiveVBProject = vbProj
| SendKeys Pwd & "~~"
| Application.VBE.CommandBars(1).FindControl(ID:=257 8,
| recursive:=True).Execute
| End Sub
|
| Sub ProtectVBProj(ByVal Pwd As String)
| Dim vbProj As Object
| Set vbProj = ThisWorkbook.VBProject
| If vbProj.Protection = 1 Then Exit Sub ' already protected
| Set Application.VBE.ActiveVBProject = vbProj
| SendKeys "+{TAB}{RIGHT}%V{+}{TAB}" & Pwd & "{TAB}" & Pwd & "~"
| Application.VBE.CommandBars(1).FindControl(ID:=257 8,
| recursive:=True).Execute
| End Sub
|
| Cheers
|
| --
| macropod
| [MVP - Microsoft Word]
|
|
| "dd" <dd.dd wrote in message
...
| | Is there a way to enable/disable the VBA password and lock project for
| | viewing, using a macro?
| |
| | Dylan
| |
| |
|
|
|
|



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Worksheet Protection Question Pat Excel Discussion (Misc queries) 1 February 4th 09 11:14 PM
Worksheet protection question Dominic Excel Discussion (Misc queries) 3 August 17th 07 07:46 PM
A Worksheet Protection Question PA New Users to Excel 1 December 8th 06 09:44 AM
Excel97 - Worksheet Protection Question Russell Plummer Excel Programming 2 February 18th 04 04:17 PM
question about worksheet protection using userinterfaceonly:=true David Brisco Excel Programming 0 February 9th 04 09:25 PM


All times are GMT +1. The time now is 06:06 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"