Open Workbook

  • Thread starter Thread starter Pedro
  • Start date Start date
P

Pedro

Hi I have the following code:

If Workbooks("Analysis.xls").Worksheets("Names").Cells(2, 3)="" Then
txtPass = InputBox("Please Insert Your Login")
Else
txtPass = Workbooks("Analysis.xls").Worksheets("Names").Cells(2,
3).Value
End If


What code should I add in order that if the Workbooks("Analysis.xls") is not
opened continues the macro still runs txtPass = InputBox("Please Insert Your
Login") in the next line

Regards,
Pedro
 
Pedro,

Here's one way

Dim txtPass
Dim oWB As Workbook

On Error Resume Next
Set oWB = Workbooks.Open("Analysis.xls")
On Error GoTo 0
If oWB Is Nothing Then
txtPass = InputBox("Please Insert Your Login")
Else
txtPass = oWB.Worksheets("Names").Cells(2, 3).Value
End If


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
On Error Resume Next
set wkbk = Workbooks("Analysis.xls")
On Error goto 0
if not wkbk is nothing then
If Workbooks("Analysis.xls").Worksheets("Names").Cells(2, 3)="" Then
txtPass = InputBox("Please Insert Your Login")
Else
txtPass = Workbooks("Analysis.xls"). _
Worksheets("Names").Cells(2,3).Value
End If
Else
Pass = InputBox("Please Insert Your Login")
End if
 
Sorry misread it, it should be
Dim txtPass
Dim oWB As Workbook

On Error Resume Next
Set oWB = Workbooks("Analysis.xls")
On Error GoTo 0
If oWB Is Nothing Then
txtPass = InputBox("Please Insert Your Login")
Else
txtPass = oWB.Worksheets("Names").Cells(2, 3).Value
End If


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Back
Top