Knowing is a workbook's VBA project has password or not

O

OMER

Is there a way to know (using VBA code) if a workbook's VBA project is
password protected?
In other words, I want to be able to know if the workbook's macros are
running on a password protected or un-protected VBA Poject?
 
D

Dave Peterson

Dim wkbk As Workbook
Set wkbk = Workbooks("yourworkbooknamehere.xls")

If wkbk.VBProject.Protection = vbext_pp_locked Then
MsgBox "it's locked"
Else
MsgBox "It's not"
End If

==========
I _think_ that this was added in xl2k. But you'll want to test it in all the
versions of excel that you're supporting.
 
O

OMER

Thank You Dave. It worked.
I changed vbext_pp_locked to 1 because the reference to VB extensibility is
not set.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top