Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 64
Default run-time error '9': subscript out of range

i get the message wheh i try to run this

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Workbooks("DATA.XLS").Close SaveChanges:=False
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7,247
Default run-time error '9': subscript out of range

An error 9 indicates that you are attempting to access an item in a
group when that item doesn't exist. Your code will throw an error 9 if
there is no open workbook with the name "Data.xls". If you want to
ignore the error, simply put "On Error Resume Next" on a line of code
just above the code that closes the workbook. Note that using Resume
to ignore an error in no way "fixes" the error; it merely tells VBA to
ignore the error, but the error can have unintended side effects.

Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]



On Tue, 8 Dec 2009 10:25:01 -0800, uk
wrote:

i get the message wheh i try to run this

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Workbooks("DATA.XLS").Close SaveChanges:=False
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default run-time error '9': subscript out of range

Hi,

That would happen if you didn't have an open workbook called data.xls
Are you sure the name is correct?
Are there any rogue spaces in the workbook name?

Mike

uk" wrote:

i get the message wheh i try to run this

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Workbooks("DATA.XLS").Close SaveChanges:=False
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 64
Default run-time error '9': subscript out of range

the data.xls workbook is open
the name is correct
there are no rogue spaces in the workbook name

"Mike H" wrote:

Hi,

That would happen if you didn't have an open workbook called data.xls
Are you sure the name is correct?
Are there any rogue spaces in the workbook name?

Mike

uk" wrote:

i get the message wheh i try to run this

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Workbooks("DATA.XLS").Close SaveChanges:=False
End Sub

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default run-time error '9': subscript out of range

The question in your previous thread was resolved when you noticed that the
extension wasn't .xls, it was .xlsm (or .xlsx).

Look to see if that continues to be a problem for you.

uk wrote:

the data.xls workbook is open
the name is correct
there are no rogue spaces in the workbook name

"Mike H" wrote:

Hi,

That would happen if you didn't have an open workbook called data.xls
Are you sure the name is correct?
Are there any rogue spaces in the workbook name?

Mike

uk" wrote:

i get the message wheh i try to run this

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Workbooks("DATA.XLS").Close SaveChanges:=False
End Sub


--

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
Error:Subscript out of range Jay Excel Discussion (Misc queries) 1 April 10th 08 10:25 PM
subscript out of range error in excell Lilivati Excel Discussion (Misc queries) 4 June 26th 06 07:15 PM
Run Time Error 9 (Subscript out of Range) for XLA file ExcelMonkey Excel Discussion (Misc queries) 3 October 5th 05 03:34 PM
Subscript out of range error moglione1 Excel Discussion (Misc queries) 2 August 30th 05 01:21 PM
Run time error 9 : Subscript out of range JAtz_DA_WAY Excel Discussion (Misc queries) 6 August 29th 05 08:26 PM


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