Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Protect\Unprotect VBA project

Hello All,

Is it possible to protect\unprotect a VBA project using
code in Excel 97 or above? I am looking for similar
functionality as protecting\unprotecting a
worksheet\workbook.

Thanks,
Rohit Thomas
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Protect\Unprotect VBA project

Rohit,

Other than using SendKeys, you cannot protect/unprotect a VBProject using
code.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
www.cpearson.com



"Rohit Thomas" wrote in message
...
Hello All,

Is it possible to protect\unprotect a VBA project using
code in Excel 97 or above? I am looking for similar
functionality as protecting\unprotecting a
worksheet\workbook.

Thanks,
Rohit Thomas



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Protect\Unprotect VBA project

Here is a example with unreliable Sendkeys


Old post from Bill Manville

------------------------
You will need to use SendKeys to unprotect the project(s) and reprotect
after replacing the modules.

Here's something to get you started:

Sub TestProtect()
Workbooks.Add.SaveAs "C:\Temp\Book1.xls"
ProtectVBProject Workbooks("Book1.xls"), "Jack"
Workbooks("Book1.xls").Close True
End Sub

Sub TestUnprotect()
Workbooks.Open "C:\Temp\Book1.xls"
UnprotectVBProject Workbooks("Book1.xls"), "Jack"
End Sub

Sub UnprotectVBProject(WB As Workbook, ByVal Password As String)
Dim vbProj As Object

Set vbProj = WB.VBProject

'can't do it if already unlocked!
If vbProj.Protection < 1 Then Exit Sub

Set Application.VBE.ActiveVBProject = vbProj

' now use lovely SendKeys to quote the project password
SendKeys Password & "~~"
Application.VBE.CommandBars(1).FindControl(Id:=257 8,
recursive:=True).Execute
End Sub

Sub ProtectVBProject(WB As Workbook, ByVal Password As String)
Dim vbProj As Object

Set vbProj = WB.VBProject

'can't do it if already locked!
If vbProj.Protection = 1 Then Exit Sub

Set Application.VBE.ActiveVBProject = vbProj

' now use lovely SendKeys to set the project password
SendKeys "+{TAB}{RIGHT}%V{+}{TAB}" & Password & "{TAB}" & _
Password & "~"

Application.VBE.CommandBars(1).FindControl(Id:=257 8,
recursive:=True).Execute

WB.Save
End Sub


Bill Manville
MVP - Microsoft Excel, Oxford, England
No email replies please - reply in newsgroup


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"Chip Pearson" wrote in message ...
Rohit,

Other than using SendKeys, you cannot protect/unprotect a VBProject using
code.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
www.cpearson.com



"Rohit Thomas" wrote in message
...
Hello All,

Is it possible to protect\unprotect a VBA project using
code in Excel 97 or above? I am looking for similar
functionality as protecting\unprotecting a
worksheet\workbook.

Thanks,
Rohit Thomas





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
Protect, unprotect Pyrite Excel Discussion (Misc queries) 0 August 15th 08 03:18 PM
Protect-Unprotect all the sheets Gary Excel Worksheet Functions 7 February 26th 07 08:13 PM
protect / unprotect VBA project by macro sylvain Excel Discussion (Misc queries) 0 July 31st 06 06:09 PM
Password - Protect, UnProtect MrAlMackay Excel Programming 5 January 19th 05 07:23 PM
Is there any way that you can protect or unprotect a group of wor. CheriT63 Excel Discussion (Misc queries) 9 January 8th 05 08:40 PM


All times are GMT +1. The time now is 11:10 PM.

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"