Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Specific macro help

I have this macro which is aimed to close a series of workbooks which may or
may not be open. it works perfectly when all the workbooks detailed are open
but tends to get periodically stuck if some of them are shut (although if I
keep running the macro eventually everything will close down. When I debug it
says

"Run time error €˜9
Subscript out of range"

is there anyway to get this macro running smoothly as it is really
frustrating that is isn't working completely the first time.

Sub SaveAndCloseWorkbooks()

Dim wbtest As Workbook

On Error Resume Next
Set wbtest = Workbooks("Bund Current Payoff.xls")
On Error GoTo 0
If Not wbtest Is Nothing Then Workbooks("Bund Current Payoff.xls").Close
SaveChanges:=True

On Error Resume Next
Set wbtest = Workbooks("Gilt Current Payoff.xls")
On Error GoTo 0
If Not wbtest Is Nothing Then Workbooks("Gilt Current Payoff.xls").Close
SaveChanges:=True

etc and so forth for 9 more workbooks

End sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Specific macro help

Sub SaveAndCloseWorkbooks()

Dim wbtest As Workbook

set wbTest = Nothing
On Error Resume Next
Set wbtest = Workbooks("Bund Current Payoff.xls")
On Error GoTo 0
If Not wbtest Is Nothing Then _
Workbooks("Bund Current Payoff.xls").Close _
SaveChanges:=True

set wbTest = Nothing
On Error Resume Next
Set wbtest = Workbooks("Gilt Current Payoff.xls")
On Error GoTo 0
If Not wbtest Is Nothing Then _
Workbooks("Gilt Current Payoff.xls").Close _
SaveChanges:=True

set wbTest = Nothing

etc and so forth for 9 more workbooks

End sub

--
Regards,
Tom Ogilvy


"Cammy" wrote:

I have this macro which is aimed to close a series of workbooks which may or
may not be open. it works perfectly when all the workbooks detailed are open
but tends to get periodically stuck if some of them are shut (although if I
keep running the macro eventually everything will close down. When I debug it
says

"Run time error €˜9
Subscript out of range"

is there anyway to get this macro running smoothly as it is really
frustrating that is isn't working completely the first time.

Sub SaveAndCloseWorkbooks()

Dim wbtest As Workbook

On Error Resume Next
Set wbtest = Workbooks("Bund Current Payoff.xls")
On Error GoTo 0
If Not wbtest Is Nothing Then Workbooks("Bund Current Payoff.xls").Close
SaveChanges:=True

On Error Resume Next
Set wbtest = Workbooks("Gilt Current Payoff.xls")
On Error GoTo 0
If Not wbtest Is Nothing Then Workbooks("Gilt Current Payoff.xls").Close
SaveChanges:=True

etc and so forth for 9 more workbooks

End sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default Specific macro help

To add to that, might want to consider the following:

Sub SaveAndCloseWorkbooks()

Dim N as Integer

For N = 1 to Workbooks.Count
With Workbooks(N)
.Close SaveChanges:=True
End With
N = N - 1
Next

End Sub

"Tom Ogilvy" wrote:

Sub SaveAndCloseWorkbooks()

Dim wbtest As Workbook

set wbTest = Nothing
On Error Resume Next
Set wbtest = Workbooks("Bund Current Payoff.xls")
On Error GoTo 0
If Not wbtest Is Nothing Then _
Workbooks("Bund Current Payoff.xls").Close _
SaveChanges:=True

set wbTest = Nothing
On Error Resume Next
Set wbtest = Workbooks("Gilt Current Payoff.xls")
On Error GoTo 0
If Not wbtest Is Nothing Then _
Workbooks("Gilt Current Payoff.xls").Close _
SaveChanges:=True

set wbTest = Nothing

etc and so forth for 9 more workbooks

End sub

--
Regards,
Tom Ogilvy


"Cammy" wrote:

I have this macro which is aimed to close a series of workbooks which may or
may not be open. it works perfectly when all the workbooks detailed are open
but tends to get periodically stuck if some of them are shut (although if I
keep running the macro eventually everything will close down. When I debug it
says

"Run time error €˜9
Subscript out of range"

is there anyway to get this macro running smoothly as it is really
frustrating that is isn't working completely the first time.

Sub SaveAndCloseWorkbooks()

Dim wbtest As Workbook

On Error Resume Next
Set wbtest = Workbooks("Bund Current Payoff.xls")
On Error GoTo 0
If Not wbtest Is Nothing Then Workbooks("Bund Current Payoff.xls").Close
SaveChanges:=True

On Error Resume Next
Set wbtest = Workbooks("Gilt Current Payoff.xls")
On Error GoTo 0
If Not wbtest Is Nothing Then Workbooks("Gilt Current Payoff.xls").Close
SaveChanges:=True

etc and so forth for 9 more workbooks

End sub

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
Macro to autofill from a specific row to a specific row Joe M. Excel Discussion (Misc queries) 2 February 5th 10 10:24 PM
Macro - specific range puiuluipui Excel Discussion (Misc queries) 3 May 10th 09 11:33 AM
specific macro on specific sheets Harshad[_2_] Excel Discussion (Misc queries) 5 October 20th 08 07:26 AM
How do I set a macro to run at specific times? Nick123 Excel Discussion (Misc queries) 1 July 26th 05 06:19 PM
Run Macro from specific cells Piers 2k Excel Programming 3 April 4th 05 01:08 PM


All times are GMT +1. The time now is 08:30 PM.

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

About Us

"It's about Microsoft Excel"