can't seem to activate an open workbook

D

dantee

I am flipping between 2 workbooks and getting an error when the vba code
reaches the line where it is supposed to pick the second workbook. Can
anyone tell me why it gives me this error? I've tried to
workbooks(filename).activate instead of windows(filename).activate and that
did not help much. Here is the error I get...

Run-time error '9':
Subscript out of range

....tells me subscript is out of range, as if I'm picking an element of an
array that is not part of the array. The code is...


Sub PPP_PORreport()

Dim stevefrieswb As String
Dim wb As Workbook
Dim PORPPPwb As String

Application.DisplayAlerts = False
Application.ScreenUpdating = True

For Each wb In Application.Workbooks
wb.Activate
If Left(wb.Name, 7) = "Monthly" Then
stevefrieswb = InputBox("What is the name of Steve Fries'
file/workbook?", "STEVE FRIES' WORKBOOK NAME", wb.Name)
If stevefrieswb = "" Then
MsgBox ("Please open Steve Fries' PPV Monthly Detail
workbook for your desired location & then re-run macro.")
Exit Sub
End If
End If
If Left(wb.Name, 7) = "POR PPP" Then
PORPPPwb = InputBox("What is the name of your POR PPP
file/workbook?", "POR PPP WORKBOOK NAME", wb.Name)
If PORPPPwb = "" Then
MsgBox ("Please open the POR PPP workbook for your desired
location & then re-run macro.")
Exit Sub
End If
End If
Next


Windows(PORPPPwb).Activate
Sheets("Future PPV").Select


Windows(stevefrieswb).Activate ' This is where the error occurs.
End Sub


Can someone tell me why this occurrs?
Thanks,
dantee.
 
D

Dave Peterson

Maybe there isn't a window or workbook open with that name???

Are you positive that the user is typing the correct name?

If the user isn't including the extension (.xls???), then I'd append it to that
workbooks(stevefrieswb & ".xls").Activate

But I'd double check the user's typing to make sure that a workbook with that
name is open.
 

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