open w/book with password

  • Thread starter tkraju via OfficeKB.com
  • Start date
T

tkraju via OfficeKB.com

The following userform code asking for a password to open another w/book..
at which line I should insert code,(what code) to open another w/book called
"sales"
Private Sub cmdLogin_Click()
With Me.TextBox1
If .Text <> ThisWorkbook.Worksheets("Sheet1") _
Range("R1").Value Then 'sheet1cell"R1" contains password
MsgBox "Invalid Password !", vbCritical
SelStart = 0
SelLength = Len(.Text)
SetFocus
Else: Unload Me
End If
End With
End Sub
 
J

JLGWhiz

The following userform code asking for a password to open another w/book..
at which line I should insert code,(what code) to open another w/book called
"sales"
Private Sub cmdLogin_Click()
With Me.TextBox1
If .Text <> ThisWorkbook.Worksheets("Sheet1") _
Range("R1").Value Then 'sheet1cell"R1" contains password
MsgBox "Invalid Password !", vbCritical
'assumes current path and xl2003 or earlier, if xl2007, need file ext.
mod.
Workbooks.Open (ThisWorkbook.Path & "\sales.xls", Password:="<password>"
SelStart = 0
SelLength = Len(.Text)
SetFocus
Else: Unload Me
End If
End With
End Sub
 
T

tkraju via OfficeKB.com

Am I to Write workbook path under brackets ?
The following userform code asking for a password to open another w/book..
at which line I should insert code,(what code) to open another w/book called
"sales"
Private Sub cmdLogin_Click()
With Me.TextBox1
If .Text <> ThisWorkbook.Worksheets("Sheet1") _
Range("R1").Value Then 'sheet1cell"R1" contains password
MsgBox "Invalid Password !", vbCritical
'assumes current path and xl2003 or earlier, if xl2007, need file ext.
mod.
Workbooks.Open (ThisWorkbook.Path & "\sales.xls", Password:="<password>"
SelStart = 0
SelLength = Len(.Text)
SetFocus
Else: Unload Me
End If
End With
End Sub
The following userform code asking for a password to open another
w/book..
[quoted text clipped - 13 lines]
End With
End Sub
 
J

JLGWhiz

Where you see <password>, means you provide that string, without the
brackets. Everything else is as written. This corrects a typo in my
original posting.

Workbooks.Open (ThisWorkbook.Path & "\sales.xls", Password:="<password>")

If you are using xl2007, the .xls file extension will need to be changed to
a four digit string, probably .xlsm

tkraju via OfficeKB.com said:
Am I to Write workbook path under brackets ?
The following userform code asking for a password to open another w/book..
at which line I should insert code,(what code) to open another w/book called
"sales"
Private Sub cmdLogin_Click()
With Me.TextBox1
If .Text <> ThisWorkbook.Worksheets("Sheet1") _
Range("R1").Value Then 'sheet1cell"R1" contains password
MsgBox "Invalid Password !", vbCritical
'assumes current path and xl2003 or earlier, if xl2007, need file ext.
mod.
Workbooks.Open (ThisWorkbook.Path & "\sales.xls", Password:="<password>"
SelStart = 0
SelLength = Len(.Text)
SetFocus
Else: Unload Me
End If
End With
End Sub
The following userform code asking for a password to open another
w/book..
[quoted text clipped - 13 lines]
End With
End Sub
 
J

JLGWhiz

I also overlooked that you have your password in cell R1 of Sheet 1 of the
workbook which is running the code. So here is a modified version that
should work. Also, on the Workbooks.Open line, if the "sales" wb is not in
the same folder as the ThisWorkbook, you will need to modify the path to
include the correct folder.

Private Sub cmdLogin_Click()
With Me.TextBox1
If .Text <> ThisWorkbook.Worksheets("Sheet1") _
Range("R1").Value Then 'sheet1cell"R1" contains password
MsgBox "Invalid Password !", vbCritical
Else
pw = ThisWorkbook.Worksheets("Sheet1").Range("R1").Value
'assumes current path and xl2003 or earlier, if xl2007, need file ext.
mod.
Workbooks.Open (ThisWorkbook.Path & "\sales.xls", Password:=pw)
SelStart = 0
SelLength = Len(.Text)
SetFocus
Else: Unload Me
End If
End With
End Sub



JLGWhiz said:
Where you see <password>, means you provide that string, without the
brackets. Everything else is as written. This corrects a typo in my
original posting.

Workbooks.Open (ThisWorkbook.Path & "\sales.xls", Password:="<password>")

If you are using xl2007, the .xls file extension will need to be changed to
a four digit string, probably .xlsm

tkraju via OfficeKB.com said:
Am I to Write workbook path under brackets ?
The following userform code asking for a password to open another w/book..
at which line I should insert code,(what code) to open another w/book called
"sales"
Private Sub cmdLogin_Click()
With Me.TextBox1
If .Text <> ThisWorkbook.Worksheets("Sheet1") _
Range("R1").Value Then 'sheet1cell"R1" contains password
MsgBox "Invalid Password !", vbCritical
'assumes current path and xl2003 or earlier, if xl2007, need file ext.
mod.
Workbooks.Open (ThisWorkbook.Path & "\sales.xls", Password:="<password>"
SelStart = 0
SelLength = Len(.Text)
SetFocus
Else: Unload Me
End If
End With
End Sub

The following userform code asking for a password to open another
w/book..
[quoted text clipped - 13 lines]
End With
End Sub
 
T

tkraju via OfficeKB.com

Thank you so much.
Where you see <password>, means you provide that string, without the
brackets. Everything else is as written. This corrects a typo in my
original posting.

Workbooks.Open (ThisWorkbook.Path & "\sales.xls", Password:="<password>")

If you are using xl2007, the .xls file extension will need to be changed to
a four digit string, probably .xlsm
Am I to Write workbook path under brackets ?
[quoted text clipped - 22 lines]
 

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