ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA in Excel Open properties (https://www.excelbanter.com/excel-programming/438353-vba-excel-open-properties.html)

mccann_mj

VBA in Excel Open properties
 
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?

--
Michael JM

Simon Lloyd[_1295_]

VBA in Excel Open properties
 

You can't as far as i know check if the password has been used to open
the workbook but you can check for read only like this:

Code:
--------------------
Private Sub Workbook_Open()
If (GetAttr(ThisWorkbook.Path & "\" & ThisWorkbook.Name) And vbReadOnly) Then
MsgBox "The Workbook is Read-Only!!", vbInformation
End If
End Sub
--------------------


*How to Save a Workbook Event Macro*
1. *Copy* the macro above placing the cursor to the left of the
code box hold the *CTRL & Left Click,* then *Right Click* selected code
and *Copy.*
2. Open your Workbook and *Right Click* on any *Worksheet's Name Tab*
3. *Left Click* on *View Code* in the pop up menu.
4. Press *ALT+F11* keys to open the *Visual Basic Editor.*
5. Press *CTRL+R* keys to shift the focus to the *Project Explorer
Window*
6. Press the *Down Arrow Key* until *ThisWorkbook* is highlighted in
blue.
7. *Press* the *Enter* key to move the cursor to the *Code Window*
8. *Paste* the macro code using *CTRL+V*
9. *Save* the macro in your Workbook using *CTRL+S*

mccann_mj;609975 Wrote:
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?

--
Michael JM



--
Simon Lloyd

Regards,
Simon Lloyd
'Microsoft Office Help' (http://www.thecodecage.com)
------------------------------------------------------------------------
Simon Lloyd's Profile: 1
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=169334

Microsoft Office Help


Matthew Herbert[_3_]

VBA in Excel Open properties
 
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

"mccann_mj" wrote:

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?

--
Michael JM


mccann_mj

VBA in Excel Open properties
 
Thanks for the info. It worked as I wanted it! (kind of rare for this project)
--
Michael JM


"Matthew Herbert" wrote:

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

"mccann_mj" wrote:

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?

--
Michael JM



All times are GMT +1. The time now is 03:32 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com