PC Review


Reply
Thread Tools Rate Thread

Activating a workbook

 
 
jseger22@yahoo.com
Guest
Posts: n/a
 
      7th Feb 2008
I have 2 files open already when I run the macro - ("Q10 - Summary
Comparison.xls") & ("USPDS_2008_Q10_Summary_data.xls"). All I am
trying to do is activate the workbook that is not currently active and
close it and then kill it. For some reason my code is not working, it
gives me the error message "Subscript out of range" and I don't know
why. The file names are correct, it is probably just something simple
but I just can't see it. Below is my code.

Sub UpdateReport()

Dim c As Long


Sheets("Raw Data").Select
For c = 1 To 16
Columns(c).EntireColumn.Hidden = False
Next c

For c = 1 To 16

If (Cells(2, c).Value) = "" Then
Columns(c).EntireColumn.Hidden = True
Else
Columns(c).EntireColumn.Hidden = False
End If
Next c

Windows("USPDS_2008_Q10_Summary_data.xls").Activate ' Gives me
error Subscript out of Range'
ActiveWindow.Close

Kill "C:\OPEX Folder\BSC Graphs\data files
\USPDS_2008_Q10_Summary_data.xls"

Windows("Q10 - Summary Comparison.xls").Activate
Sheets("Q10 - U.S. PDS Summary").Select

ActiveSheet.Shapes("Button 4").Select
Selection.Delete

ActiveWorkbook.SaveAs Filename:= _
"C:\OPEX Folder\BSC Graphs\Q10 - Summary Comparison " &
Format(Date, "mmddyyyy") & ".xls" _
, FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

End Sub
 
Reply With Quote
 
 
 
 
Chip Pearson
Guest
Posts: n/a
 
      7th Feb 2008
Change
Windows("USPDS_2008_Q10_Summary_data.xls").Activate
ActiveWindow.Close

to
Workbooks("USPDS_2008_Q10_Summary_data.xls").Activate
ActiveWorkbook.Close SaveChanges:=True ' or False, your choice
or simply
Workbooks("USPDS_2008_Q10_Summary_data.xls").Close SaveChanges:=True


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2008
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


<(E-Mail Removed)> wrote in message
news:0fa0f038-4036-4519-a052-(E-Mail Removed)...
>I have 2 files open already when I run the macro - ("Q10 - Summary
> Comparison.xls") & ("USPDS_2008_Q10_Summary_data.xls"). All I am
> trying to do is activate the workbook that is not currently active and
> close it and then kill it. For some reason my code is not working, it
> gives me the error message "Subscript out of range" and I don't know
> why. The file names are correct, it is probably just something simple
> but I just can't see it. Below is my code.
>
> Sub UpdateReport()
>
> Dim c As Long
>
>
> Sheets("Raw Data").Select
> For c = 1 To 16
> Columns(c).EntireColumn.Hidden = False
> Next c
>
> For c = 1 To 16
>
> If (Cells(2, c).Value) = "" Then
> Columns(c).EntireColumn.Hidden = True
> Else
> Columns(c).EntireColumn.Hidden = False
> End If
> Next c
>
> Windows("USPDS_2008_Q10_Summary_data.xls").Activate ' Gives me
> error Subscript out of Range'
> ActiveWindow.Close
>
> Kill "C:\OPEX Folder\BSC Graphs\data files
> \USPDS_2008_Q10_Summary_data.xls"
>
> Windows("Q10 - Summary Comparison.xls").Activate
> Sheets("Q10 - U.S. PDS Summary").Select
>
> ActiveSheet.Shapes("Button 4").Select
> Selection.Delete
>
> ActiveWorkbook.SaveAs Filename:= _
> "C:\OPEX Folder\BSC Graphs\Q10 - Summary Comparison " &
> Format(Date, "mmddyyyy") & ".xls" _
> , FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
> ReadOnlyRecommended:=False, CreateBackup:=False
>
> End Sub


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
activating a workbook Almagg via OfficeKB.com Microsoft Excel Programming 3 16th Apr 2007 08:41 PM
Re: Activating Workbook Chip Pearson Microsoft Excel Programming 3 30th Dec 2006 01:53 AM
Re: Activating Workbook Rod Gill Microsoft Excel Programming 1 29th Dec 2006 10:09 PM
Activating a workbook =?Utf-8?B?Qm9sZGll?= Microsoft Excel Programming 5 19th Jul 2006 03:15 AM
Activating a workbook help bmwmcrider Microsoft Excel Programming 1 21st Oct 2003 01:48 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:46 PM.