Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 98
Default Exit sub only and only if there is an error in the procedure.

Hi,

I want a code which will exit the macro(Procedure) only and only if
there an error in the procedure.

Here is the code which i wrote but after the error message it
continues to run the next procedure and i want it to it to exit. If
there is no error it comes on the exit sub and stops the macro.

Sub TLPColl()

On error goto Jumpexit

workbook.open "XXXX"

Jumpexit:
Msgbox "Kindly mention the path where the raw file is saved in Cell D5
of Summary Tab"

Exit sub

'here are my procedure

Exit Sub

Kindly help.

Regards

Heera
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default Exit sub only and only if there is an error in the procedure.

Hi

I would rather check if the file exists than rely on an error.

Look at this:

Sub TLPColl()

Set fs = CreateObject("Scripting.FileSystemObject")

a = fs.Fileexists(MyFile)
If a = False Then
' File don't exists in current folder
MsgBox "Kindly mention the path where the raw file is saved in Cell D5
of Summary Tab"
Exit Sub
Exit Sub

Workbook.Open Filename:="XXXX.xls"

'here are my procedure

End Sub

Regards,
Per

"Heera" skrev i meddelelsen
...
Hi,

I want a code which will exit the macro(Procedure) only and only if
there an error in the procedure.

Here is the code which i wrote but after the error message it
continues to run the next procedure and i want it to it to exit. If
there is no error it comes on the exit sub and stops the macro.

Sub TLPColl()

On error goto Jumpexit

workbook.open "XXXX"

Jumpexit:
Msgbox "Kindly mention the path where the raw file is saved in Cell D5
of Summary Tab"

Exit sub

'here are my procedure

Exit Sub

Kindly help.

Regards

Heera


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Exit sub only and only if there is an error in the procedure.

I think I would put it in this order. that way, if it goes to Jumpexit, it
is unlikelty to run the main code.

Sub TLPColl()

On error goto Jumpexit

workbook.open "XXXX"


'here are my procedure

Jumpexit:
Msgbox "Kindly mention the path where the raw file is saved in Cell D5
of Summary Tab"

Exit sub




"Heera" wrote:

Hi,

I want a code which will exit the macro(Procedure) only and only if
there an error in the procedure.

Here is the code which i wrote but after the error message it
continues to run the next procedure and i want it to it to exit. If
there is no error it comes on the exit sub and stops the macro.

Sub TLPColl()

On error goto Jumpexit

workbook.open "XXXX"

Jumpexit:
Msgbox "Kindly mention the path where the raw file is saved in Cell D5
of Summary Tab"

Exit sub

'here are my procedure

Exit Sub

Kindly help.

Regards

Heera

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
Exit a Procedure from a Sub within a sub [email protected] Excel Discussion (Misc queries) 5 June 25th 08 06:59 PM
run procedure when exit design mode Wim SKW Excel Programming 3 July 11th 07 12:21 PM
run procedure when exit design mode Wim SKW Excel Discussion (Misc queries) 1 July 11th 07 09:24 AM
What is procedure to exit formula auditing mode? W8 Excel Discussion (Misc queries) 3 February 14th 05 08:05 PM
Opening a UserForm causes a crash in the Exit procedure (Which is never called) Brent McIntyre Excel Programming 0 May 12th 04 12:37 PM


All times are GMT +1. The time now is 12:34 AM.

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"