melodramatic
Board Regular
- Joined
- Apr 28, 2003
- Messages
- 180
- Office Version
- 365
- Platform
- Windows
I know I've done this before - I checked my VBA on other files (that work), and it should work. But, it doesn't. Can someone figure out what I might be doing wrong here?
Have a commandbutton to open a file. If the user is me or the file owner, then it opens it with the password. If the user is anyone else, then it opens it readonly. The password itself is in hidden cell O2. I double-checked, and yes, the cell does show the correct password. (In fact, you'll see where I did a msgbox to make sure that password was correct.)
What happens is the file opens, and pauses for me to enter the password, as if I didn't have the "Password:=Pwd" written in the line.
Is there something I'm just not seeing?
Thanks in advance for any help on this!
Have a commandbutton to open a file. If the user is me or the file owner, then it opens it with the password. If the user is anyone else, then it opens it readonly. The password itself is in hidden cell O2. I double-checked, and yes, the cell does show the correct password. (In fact, you'll see where I did a msgbox to make sure that password was correct.)
What happens is the file opens, and pauses for me to enter the password, as if I didn't have the "Password:=Pwd" written in the line.
Is there something I'm just not seeing?
Thanks in advance for any help on this!
VBA Code:
Private Sub CommandButton3_Click()
' This macro opens the weekly Lab Rental file for edit (mmay or dmcknight only) or view
' Written by Melody October May
' Created May 26, 2020
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim Pwd As String
Dim NetWorkFolder As String
Dim MasterFile As String
Pwd = Range("O2")
NetWorkFolder = Range("D20")
MasterFile = Range("D23")
If Environ("username") = "mmay" Or Environ("username") = "dmcknight" Then
MsgBox Pwd
Workbooks.Open FileName:=NetWorkFolder & "\" & MasterFile, Password:=Pwd, ignorereadonlyrecommended:=True 'This is where I'm getting my error - it's stopping for me to enter the password at the file open box
Else
Workbooks.Open FileName:=NetWorkFolder & "\" & MasterFile, ReadOnly:=True, ignorereadonlyrecommended:=True
End If
End Sub