Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Trying to close Excel file nut get error msg

Greetings,

I'm created a new Excel file on the fly and copying a specific
worksheet into that new file. This part is fine, until I try to close
that new file (see last file of code) and get the error msg:

Run time error 9
subscript out of range.

Here's the logic in the code:


newFname = "NewEXCELfile.XLS"
Set NewWks = Workbooks.Add(1).Worksheets(1)
With NewWks
.Parent.SaveAs FileName:=newFname, FileFormat:=xlWorkbookNormal
End With
NewWks.Name = "MyNewSheet"
Set destrange = NewWks.Range("A1:z100")
Set sourceRange = ThisWorkbook.Sheets("SHEET1").Range("A1:z100")
sourceRange.Copy
destrange.PasteSpecial xlPasteColumnWidths, , False, False
destrange.PasteSpecial xlPasteFormats, , False, False
destrange.PasteSpecial (xlPasteFormulas)
application.CutCopyMode = False
Workbooks(newFname).Close

Many thanks...

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Trying to close Excel file nut get error msg

On Aug 25, 9:16 am, LetMeDoIt wrote:
Greetings,

I'm created a new Excel file on the fly and copying a specific
worksheet into that new file. This part is fine, until I try to close
that new file (see last file of code) and get the error msg:

Run time error 9
subscript out of range.

Here's the logic in the code:

newFname = "NewEXCELfile.XLS"
Set NewWks = Workbooks.Add(1).Worksheets(1)
With NewWks
.Parent.SaveAs FileName:=newFname, FileFormat:=xlWorkbookNormal
End With
NewWks.Name = "MyNewSheet"
Set destrange = NewWks.Range("A1:z100")
Set sourceRange = ThisWorkbook.Sheets("SHEET1").Range("A1:z100")
sourceRange.Copy
destrange.PasteSpecial xlPasteColumnWidths, , False, False
destrange.PasteSpecial xlPasteFormats, , False, False
destrange.PasteSpecial (xlPasteFormulas)
application.CutCopyMode = False
Workbooks(newFname).Close

Many thanks...


I was able to run your code without any errors... Is all of your code
in the list you provided? I'm using xl2007, what version are you
using?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Trying to close Excel file nut get error msg

Thanks for looking into it. I'm using Office 2003 running XP on a
laptop. Maybe I should try this on windows 2000.

On Aug 25, 3:40 pm, Ferris wrote:
On Aug 25, 9:16 am, LetMeDoIt wrote:





Greetings,


I'm created a new Excel file on the fly and copying a specific
worksheet into that new file. This part is fine, until I try to close
that new file (see last file of code) and get the error msg:


Run time error 9
subscript out of range.


Here's the logic in the code:


newFname = "NewEXCELfile.XLS"
Set NewWks = Workbooks.Add(1).Worksheets(1)
With NewWks
.Parent.SaveAs FileName:=newFname, FileFormat:=xlWorkbookNormal
End With
NewWks.Name = "MyNewSheet"
Set destrange = NewWks.Range("A1:z100")
Set sourceRange = ThisWorkbook.Sheets("SHEET1").Range("A1:z100")
sourceRange.Copy
destrange.PasteSpecial xlPasteColumnWidths, , False, False
destrange.PasteSpecial xlPasteFormats, , False, False
destrange.PasteSpecial (xlPasteFormulas)
application.CutCopyMode = False
Workbooks(newFname).Close


Many thanks...


I was able to run your code without any errors... Is all of your code
in the list you provided? I'm using xl2007, what version are you
using?- Hide quoted text -

- Show quoted text -



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Trying to close Excel file nut get error msg

I am using XP Office 2003 and it ran OK on mine.

"LetMeDoIt" wrote:

Thanks for looking into it. I'm using Office 2003 running XP on a
laptop. Maybe I should try this on windows 2000.

On Aug 25, 3:40 pm, Ferris wrote:
On Aug 25, 9:16 am, LetMeDoIt wrote:





Greetings,


I'm created a new Excel file on the fly and copying a specific
worksheet into that new file. This part is fine, until I try to close
that new file (see last file of code) and get the error msg:


Run time error 9
subscript out of range.


Here's the logic in the code:


newFname = "NewEXCELfile.XLS"
Set NewWks = Workbooks.Add(1).Worksheets(1)
With NewWks
.Parent.SaveAs FileName:=newFname, FileFormat:=xlWorkbookNormal
End With
NewWks.Name = "MyNewSheet"
Set destrange = NewWks.Range("A1:z100")
Set sourceRange = ThisWorkbook.Sheets("SHEET1").Range("A1:z100")
sourceRange.Copy
destrange.PasteSpecial xlPasteColumnWidths, , False, False
destrange.PasteSpecial xlPasteFormats, , False, False
destrange.PasteSpecial (xlPasteFormulas)
application.CutCopyMode = False
Workbooks(newFname).Close


Many thanks...


I was able to run your code without any errors... Is all of your code
in the list you provided? I'm using xl2007, what version are you
using?- Hide quoted text -

- Show quoted text -




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Trying to close Excel file nut get error msg

I rewrote part of the code to handle the closing. Many thanks for
testing this.
regards.

On Aug 25, 5:14 pm, JLGWhiz wrote:
I am using XP Office 2003 and it ran OK on mine.



"LetMeDoIt" wrote:
Thanks for looking into it. I'm using Office 2003 running XP on a
laptop. Maybe I should try this on windows 2000.


On Aug 25, 3:40 pm, Ferris wrote:
On Aug 25, 9:16 am, LetMeDoIt wrote:


Greetings,


I'm created a new Excel file on the fly and copying a specific
worksheet into that new file. This part is fine, until I try to close
that new file (see last file of code) and get the error msg:


Run time error 9
subscript out of range.


Here's the logic in the code:


newFname = "NewEXCELfile.XLS"
Set NewWks = Workbooks.Add(1).Worksheets(1)
With NewWks
.Parent.SaveAs FileName:=newFname, FileFormat:=xlWorkbookNormal
End With
NewWks.Name = "MyNewSheet"
Set destrange = NewWks.Range("A1:z100")
Set sourceRange = ThisWorkbook.Sheets("SHEET1").Range("A1:z100")
sourceRange.Copy
destrange.PasteSpecial xlPasteColumnWidths, , False, False
destrange.PasteSpecial xlPasteFormats, , False, False
destrange.PasteSpecial (xlPasteFormulas)
application.CutCopyMode = False
Workbooks(newFname).Close


Many thanks...


I was able to run your code without any errors... Is all of your code
in the list you provided? I'm using xl2007, what version are you
using?- Hide quoted text -


- Show quoted text -- Hide quoted text -


- Show quoted text -



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
error message : I can't close my PERSONAL.XLS file Roger[_2_] New Users to Excel 2 November 14th 09 09:56 PM
Everytime i close an excel file, it creates a new backup file p Excel Discussion (Misc queries) 3 November 22nd 07 08:13 AM
Let me save/close EXCEL if a formula I put in has an error in it Tony Borg Setting up and Configuration of Excel 1 September 2nd 06 04:13 AM
Error trying to close down dbase IV file used for input to excel don Excel Programming 1 June 4th 06 02:35 AM
Adding an error message at close of file when criteria are met Dave Excel Discussion (Misc queries) 3 August 12th 05 07:56 PM


All times are GMT +1. The time now is 11:56 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"