LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Won't close w/routine

With help from the experts here I have come up with the following routine
that creates a copy of the open workbook then performs calculations and saves
the data then opens the original workbook and paste in the data and then
closes and deletes the created workbook.

The problem is that when it gets to "Workbooks(sName).Close
SaveChanges:=False" in the Sub DeleteTempWB() it stops and shows a run time
error #9 "script out of range". Yet when I run DeleteTempWB from within the
workbook it works fine. I put the routine in differant areas and I get the
same. If I include another routine/procedure from the workbook, they work
fine. Any ideas would will be appreciated.

The code is

Sub ChangeToEvenProcedure()
Application.Run "CreateTempWB" - creates a copy w/saveas
Application.Run "ChangeToEven" - does the calculations and copies 12 cells
Application.Run "OpenOriginal" - opens the original and pastes in the data
Application.Run "DeleteTempWB" - close and delete the copy

Sub OpenOriginal()
sName = ThisWorkbook.FullName
sName = Left(sName, Len(sName) - 5) & ".xls"
Workbooks.Open sName
Sheets("Sheet1").Select
Range("C31").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
End Sub


Sub DeleteTempWB()
sName = ThisWorkbook.Name
sName = Left(sName, Len(sName) - 4) & "X.xls"
Workbooks(sName).Close SaveChanges:=False
Kill ThisWorkbook.Path & "\" & sName
End Sub



 
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
why do all excel worksheets/workbooks close when I close one? Penny Excel Discussion (Misc queries) 1 November 29th 06 03:49 AM
Not close thead when I close excel wakeup[_3_] Excel Programming 0 December 5th 05 08:57 AM
Excel shoud not close all active books when clicking close button technomike Excel Discussion (Misc queries) 0 June 10th 05 05:35 PM
excel - Windows close button (x) should only close active workboo. CoffeeAdict Setting up and Configuration of Excel 3 February 8th 05 04:30 AM
Close routine Jim Smythe Excel Programming 2 November 25th 03 12:59 PM


All times are GMT +1. The time now is 04:27 AM.

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"