Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9
Default can't seem to activate an open workbook

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.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default can't seem to activate an open workbook

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.



dantee wrote:

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.


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to auto activate macro when file open ? bonzio Excel Worksheet Functions 1 December 16th 05 02:45 PM
Activate Workbook Dolphinv4 Excel Discussion (Misc queries) 2 October 22nd 05 01:45 PM
Activate new workbook with unknown name rt10516 Excel Discussion (Misc queries) 3 August 24th 05 05:40 AM
Activate a workbook from a selection GregR Excel Discussion (Misc queries) 1 April 7th 05 03:25 AM
Workbook.activate Jeff Excel Discussion (Misc queries) 1 December 13th 04 10:22 PM


All times are GMT +1. The time now is 12:34 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"