VBA in Excel Open properties

M

mccann_mj

I have an Excel 2007 file that when opened, asks for a password, but if you
don't have the password, will open as a read only (using the "Save As",
tools, General Options). I have a userform that opens upon opening the
workbook. I'm trying to find a way that if the password is not used, the form
does not open up; if the password is used, the form pops up. Is there an open
property I can "read" to determine if the password was used?
 
M

Matthew Herbert

Michael,

The .ReadOnly property should tell you if the file is in a ReadOnly state or
not.

So, your Workbook_Open event could look something like the following:

Private Sub Workbook_Open()
If ThisWorkbook.ReadOnly Then
'add code for the file being in a ReadOnly state
End If
End Sub

Best,

Matthew Herbert
 

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