Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default how to stop a macro


I ask user to choose a file, then I use this file to do sth. But if h
cancels, I want to stop my macro.

For example,

Code
-------------------
Dim s_file As String

s_file = Application.GetOpenFilename("Fichiers office, *.xls")
If s_file = "False" Then
' I want stop my macro here
End If
' ..
-------------------


Regards

--
Guendal

-----------------------------------------------------------------------
Guendalf's Profile: http://www.excelforum.com/member.php...fo&userid=2448
View this thread: http://www.excelforum.com/showthread.php?threadid=38086

  #2   Report Post  
Posted to microsoft.public.excel.programming
JPW JPW is offline
external usenet poster
 
Posts: 1
Default how to stop a macro


Use the statement "Exit Sub" if you are in a sub, or "Exit Function" i
you are in a function

--
JP
-----------------------------------------------------------------------
JPW's Profile: http://www.excelforum.com/member.php...fo&userid=2448
View this thread: http://www.excelforum.com/showthread.php?threadid=38086

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default how to stop a macro


If s_file = "False" Then
END
End I

--
anilsolipura
-----------------------------------------------------------------------
anilsolipuram's Profile: http://www.excelforum.com/member.php...fo&userid=1627
View this thread: http://www.excelforum.com/showthread.php?threadid=38086

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default how to stop a macro

Note that using End stops everything immediately with no termination events.
Global variables are zeroed for example. This may be what you want, but
most don't.

--
Regards,
Tom Ogilvy


"anilsolipuram"
wrote in message
news:anilsolipuram.1qzc75_1119363209.066@excelforu m-nospam.com...

If s_file = "False" Then
END
End If


--
anilsolipuram
------------------------------------------------------------------------
anilsolipuram's Profile:

http://www.excelforum.com/member.php...o&userid=16271
View this thread: http://www.excelforum.com/showthread...hreadid=380861



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default how to stop a macro

END

Be careful using the End statement. It does indeed stop VBA code
execution, but it also clears all global variables, resetting
them to their uninitialized default values. This may cause
problems with other procedures.

In general, Exit Sub or Exit Function is the better solution.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"anilsolipuram"
wrote
in message
news:anilsolipuram.1qzc75_1119363209.066@excelforu m-nospam.com...

If s_file = "False" Then
END
End If


--
anilsolipuram
------------------------------------------------------------------------
anilsolipuram's Profile:
http://www.excelforum.com/member.php...o&userid=16271
View this thread:
http://www.excelforum.com/showthread...hreadid=380861





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default how to stop a macro


anilsolipuram Wrote:
If s_file = "False" Then
END
End If


It's what I was looking for. :)
Thanks.


--
Guendalf


------------------------------------------------------------------------
Guendalf's Profile: http://www.excelforum.com/member.php...o&userid=24480
View this thread: http://www.excelforum.com/showthread...hreadid=380861

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
Macro Stop LMP Excel Worksheet Functions 3 April 28th 08 07:33 PM
Stop running a macro in the middle of a macro gmunro Excel Programming 3 June 9th 05 06:00 PM
Macro: With Stop it works. Without Stop it doesn't. Don Wiss Excel Programming 2 October 12th 04 10:49 AM
Start Macro / Stop Macro / Restart Macro Pete[_13_] Excel Programming 2 November 21st 03 05:04 PM
How do I stop a macro Steve[_41_] Excel Programming 2 September 23rd 03 03:54 PM


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