PC Review


Reply
Thread Tools Rate Thread

before close runtime error 9

 
 
stewdizzle
Guest
Posts: n/a
 
      6th Jan 2007
I am trying to get the code to delete a sheet, save, then close the
workbook. Right now it deletes the sheet, saves but then I get a Run
time Error "9" subscript out of range. I have the code below. Please
tell me what I am doing wrong.

Private Sub workbook_beforeclose(cancel As Boolean)
Application.DisplayAlerts = False
ActiveWorkbook.Sheets("sheet1").Delete
Application.DisplayAlerts = True
ActiveWorkbook.Save
ActiveWorkbook.Close
End Sub

 
Reply With Quote
 
 
 
 
=?Utf-8?B?SkxHV2hpeg==?=
Guest
Posts: n/a
 
      6th Jan 2007
How many sheets in the workbook?

"stewdizzle" wrote:

> I am trying to get the code to delete a sheet, save, then close the
> workbook. Right now it deletes the sheet, saves but then I get a Run
> time Error "9" subscript out of range. I have the code below. Please
> tell me what I am doing wrong.
>
> Private Sub workbook_beforeclose(cancel As Boolean)
> Application.DisplayAlerts = False
> ActiveWorkbook.Sheets("sheet1").Delete
> Application.DisplayAlerts = True
> ActiveWorkbook.Save
> ActiveWorkbook.Close
> End Sub
>
>

 
Reply With Quote
 
=?Utf-8?B?SkxHV2hpeg==?=
Guest
Posts: n/a
 
      6th Jan 2007
Also try Workbooks(ThisWorkbook).Close

"stewdizzle" wrote:

> I am trying to get the code to delete a sheet, save, then close the
> workbook. Right now it deletes the sheet, saves but then I get a Run
> time Error "9" subscript out of range. I have the code below. Please
> tell me what I am doing wrong.
>
> Private Sub workbook_beforeclose(cancel As Boolean)
> Application.DisplayAlerts = False
> ActiveWorkbook.Sheets("sheet1").Delete
> Application.DisplayAlerts = True
> ActiveWorkbook.Save
> ActiveWorkbook.Close
> End Sub
>
>

 
Reply With Quote
 
stewdizzle
Guest
Posts: n/a
 
      6th Jan 2007
two worksheets one named budget and the other is named sheet1

On Jan 5, 10:23 pm, JLGWhiz <JLGW...@discussions.microsoft.com> wrote:
> Also try Workbooks(ThisWorkbook).Close
>
> "stewdizzle" wrote:
> > I am trying to get the code to delete a sheet, save, then close the
> > workbook. Right now it deletes the sheet, saves but then I get a Run
> > time Error "9" subscript out of range. I have the code below. Please
> > tell me what I am doing wrong.

>
> > Private Sub workbook_beforeclose(cancel As Boolean)
> > Application.DisplayAlerts = False
> > ActiveWorkbook.Sheets("sheet1").Delete
> > Application.DisplayAlerts = True
> > ActiveWorkbook.Save
> > ActiveWorkbook.Close
> > End Sub


 
Reply With Quote
 
stewdizzle
Guest
Posts: n/a
 
      6th Jan 2007
Using Workbooks(ThisWorkbook).Close gets rid of the error 9 but now i
get error 13 type mismatch. Everything works up until the close
command. Here is the code.

Private Sub workbook_beforeclose(cancel As Boolean)
Application.DisplayAlerts = False
ActiveWorkbook.Sheets("sheet1").Delete
Application.DisplayAlerts = True
ActiveWorkbook.Save
Workbooks(ThisWorkbook).Close
End Sub


On Jan 6, 10:08 am, "stewdizzle" <smccallis...@gmail.com> wrote:
> two worksheets one named budget and the other is named sheet1
>
> On Jan 5, 10:23 pm, JLGWhiz <JLGW...@discussions.microsoft.com> wrote:
>
> > Also try Workbooks(ThisWorkbook).Close

>
> > "stewdizzle" wrote:
> > > I am trying to get the code to delete a sheet, save, then close the
> > > workbook. Right now it deletes the sheet, saves but then I get a Run
> > > time Error "9" subscript out of range. I have the code below. Please
> > > tell me what I am doing wrong.

>
> > > Private Sub workbook_beforeclose(cancel As Boolean)
> > > Application.DisplayAlerts = False
> > > ActiveWorkbook.Sheets("sheet1").Delete
> > > Application.DisplayAlerts = True
> > > ActiveWorkbook.Save
> > > ActiveWorkbook.Close
> > > End Sub


 
Reply With Quote
 
stewdizzle
Guest
Posts: n/a
 
      6th Jan 2007
I'm not sure if this means anything but application.quit works fine.
for some reason i can't get it to just close the workbook.

On Jan 6, 10:16 am, "stewdizzle" <smccallis...@gmail.com> wrote:
> Using Workbooks(ThisWorkbook).Close gets rid of the error 9 but now i
> get error 13 type mismatch. Everything works up until the close
> command. Here is the code.
>
> Private Sub workbook_beforeclose(cancel As Boolean)
> Application.DisplayAlerts = False
> ActiveWorkbook.Sheets("sheet1").Delete
> Application.DisplayAlerts = True
> ActiveWorkbook.Save
> Workbooks(ThisWorkbook).Close
> End Sub
>
> On Jan 6, 10:08 am, "stewdizzle" <smccallis...@gmail.com> wrote:
>
> > two worksheets one named budget and the other is named sheet1

>
> > On Jan 5, 10:23 pm, JLGWhiz <JLGW...@discussions.microsoft.com> wrote:

>
> > > Also try Workbooks(ThisWorkbook).Close

>
> > > "stewdizzle" wrote:
> > > > I am trying to get the code to delete a sheet, save, then close the
> > > > workbook. Right now it deletes the sheet, saves but then I get a Run
> > > > time Error "9" subscript out of range. I have the code below. Please
> > > > tell me what I am doing wrong.

>
> > > > Private Sub workbook_beforeclose(cancel As Boolean)
> > > > Application.DisplayAlerts = False
> > > > ActiveWorkbook.Sheets("sheet1").Delete
> > > > Application.DisplayAlerts = True
> > > > ActiveWorkbook.Save
> > > > ActiveWorkbook.Close
> > > > End Sub


 
Reply With Quote
 
Jim Cone
Guest
Posts: n/a
 
      6th Jan 2007
It appears that you have already told Excel to close the workbook
as you are using the beforeclose event.
So, try eliminating the last line of your code and see what happens.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"stewdizzle" <(E-Mail Removed)>
wrote in message
I'm not sure if this means anything but application.quit works fine.
for some reason i can't get it to just close the workbook.

On Jan 6, 10:16 am, "stewdizzle" <smccallis...@gmail.com> wrote:
> Using Workbooks(ThisWorkbook).Close gets rid of the error 9 but now i
> get error 13 type mismatch. Everything works up until the close
> command. Here is the code.
>
> Private Sub workbook_beforeclose(cancel As Boolean)
> Application.DisplayAlerts = False
> ActiveWorkbook.Sheets("sheet1").Delete
> Application.DisplayAlerts = True
> ActiveWorkbook.Save
> Workbooks(ThisWorkbook).Close
> End Sub
>
> On Jan 6, 10:08 am, "stewdizzle" <smccallis...@gmail.com> wrote:
>
> > two worksheets one named budget and the other is named sheet1

>
> > On Jan 5, 10:23 pm, JLGWhiz <JLGW...@discussions.microsoft.com> wrote:

>
> > > Also try Workbooks(ThisWorkbook).Close

>
> > > "stewdizzle" wrote:
> > > > I am trying to get the code to delete a sheet, save, then close the
> > > > workbook. Right now it deletes the sheet, saves but then I get a Run
> > > > time Error "9" subscript out of range. I have the code below. Please
> > > > tell me what I am doing wrong.

>
> > > > Private Sub workbook_beforeclose(cancel As Boolean)
> > > > Application.DisplayAlerts = False
> > > > ActiveWorkbook.Sheets("sheet1").Delete
> > > > Application.DisplayAlerts = True
> > > > ActiveWorkbook.Save
> > > > ActiveWorkbook.Close
> > > > End Sub


 
Reply With Quote
 
stewdizzle
Guest
Posts: n/a
 
      6th Jan 2007
Thanks for catching it. That did the trick.

On Jan 6, 1:01 pm, "Jim Cone" <jim.cone...@rcn.comXXX> wrote:
> It appears that you have already told Excel to close the workbook
> as you are using the beforeclose event.
> So, try eliminating the last line of your code and see what happens.
> --
> Jim Cone
> San Francisco, USAhttp://www.realezsites.com/bus/primitivesoftware
>
> "stewdizzle" <smccallis...@gmail.com>
> wrote in message
> I'm not sure if this means anything but application.quit works fine.
> for some reason i can't get it to just close the workbook.
>
> On Jan 6, 10:16 am, "stewdizzle" <smccallis...@gmail.com> wrote:
>
> > Using Workbooks(ThisWorkbook).Close gets rid of the error 9 but now i
> > get error 13 type mismatch. Everything works up until the close
> > command. Here is the code.

>
> > Private Sub workbook_beforeclose(cancel As Boolean)
> > Application.DisplayAlerts = False
> > ActiveWorkbook.Sheets("sheet1").Delete
> > Application.DisplayAlerts = True
> > ActiveWorkbook.Save
> > Workbooks(ThisWorkbook).Close
> > End Sub

>
> > On Jan 6, 10:08 am, "stewdizzle" <smccallis...@gmail.com> wrote:

>
> > > two worksheets one named budget and the other is named sheet1

>
> > > On Jan 5, 10:23 pm, JLGWhiz <JLGW...@discussions.microsoft.com> wrote:

>
> > > > Also try Workbooks(ThisWorkbook).Close

>
> > > > "stewdizzle" wrote:
> > > > > I am trying to get the code to delete a sheet, save, then close the
> > > > > workbook. Right now it deletes the sheet, saves but then I get a Run
> > > > > time Error "9" subscript out of range. I have the code below. Please
> > > > > tell me what I am doing wrong.

>
> > > > > Private Sub workbook_beforeclose(cancel As Boolean)
> > > > > Application.DisplayAlerts = False
> > > > > ActiveWorkbook.Sheets("sheet1").Delete
> > > > > Application.DisplayAlerts = True
> > > > > ActiveWorkbook.Save
> > > > > ActiveWorkbook.Close
> > > > > 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
in middle of letter Runtime error and must close =?Utf-8?B?TWljaGFlbCBCYWxkaWdhcmE=?= Microsoft Word Document Management 1 30th Mar 2007 06:18 AM
WORD runtime error when close OUTLOOK is NOT works or adobe =?Utf-8?B?VGVyZXNhOA==?= Microsoft Word Document Management 0 12th Jul 2006 08:50 AM
Installation Error: Visual C++ Runtime Linrary Runtime Error =?Utf-8?B?Sm9obiBXZXN0bGFrZQ==?= Windows Vista Installation 7 13th Jun 2006 07:56 AM
Visual c++ runtime Library runtime error. - c runtime error.jpg (0/1) ... Windows XP Accessibility 0 1st May 2004 06:26 PM
scrolling, failure to close, runtime error Teri Microsoft Outlook Discussion 0 4th Dec 2003 06:18 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:58 AM.