473,385 Members | 1,185 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

VB & Excel - how to stop a function

I have the following problem. Suppose I added a button to my worksheet
and when user clicks the button a function starts. Now, as long as
this function is running the worksheet is not active. The question is:
is it possible to stop this function from the worksheet, for example
is it possible to add another button to the worksheet so that the user
could click this button and stop the function that is running after he
clicked the first button?

rgds.

Jakub
Jul 17 '05 #1
1 15469

"Jakub" <jz*****@yahoo.co.uk> wrote in message
news:f3*************************@posting.google.co m...
I have the following problem. Suppose I added a button to my worksheet
and when user clicks the button a function starts. Now, as long as
this function is running the worksheet is not active. The question is:
is it possible to stop this function from the worksheet, for example
is it possible to add another button to the worksheet so that the user
could click this button and stop the function that is running after he
clicked the first button?

rgds.

Jakub


You need to do two things in the function do allow this to happen.

One is to include DoEvents in the loop, so that a second button click has a
chance to register.

The other is to put a check in the loop, so that if a certain variable is set,
the loop stops. You set this variable false when the first button is clicked,
and true when the second button is clicked.

Here is an example. Put the code in a module, then assign StartIt to one button,
and StopIt to another.

Dim Flag As Boolean

Public Sub StartIt()
Flag = False
Call RunLoop
End Sub

Public Sub StopIt()
Flag = True
End Sub

Sub RunLoop()
Dim x As Double
Dim n As Long
Dim nCnt As Long

Do
x = 32.4

For n = 1 To 1000
' act busy
x = Sqr(x)
Next n

nCnt = nCnt + 1

DoEvents

Loop Until Flag = True

MsgBox nCnt & " loops."

End Sub


Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Mike | last post by:
Please help. I am using object.quit in an attempt to quit an excel application that I started with createobject ("Excel.Application"). The code executes, but does not stop the application. When...
1
by: Ben | last post by:
I have written a procedure which calls the CORREL function of Excel to run correlation analysis on two arrays, then populate a table with the resulting correlation coefficient. This process loops...
11
by: Mr. Smith | last post by:
Hello all, My code can successfully open, write to, format and save several worksheets in a workbook then save it by a given name, close and quit excel. My problem is that if I try and do it...
1
by: u7djo | last post by:
Hi, I'm currently building a function in Access that creates an Excel spreadsheet but it doesn't look like the Excel object is being destroyed correctly as the Excel module is still showing in the...
0
by: Bob | last post by:
Hey, Ive got a simple question but I cant figure out the answer. Im not the greatest of programmers. Im trying to copy stuff over from Word to Excel using C#. But the problem Im having is when...
1
by: Ray Ackley | last post by:
I'm experiencing a threading problem that's really perplexing me. I have a multithreaded application that reads car ECU information that's sent over the serial port by the ECU and received by the...
6
by: Mark Rae | last post by:
Hi, My client has asked me to provide a "quick and dirty" way to export the contents of a DataGrid to both Excel for analysis and Word for editing and printing, so I'm investigating client-side...
15
RMWChaos
by: RMWChaos | last post by:
In my ongoing effort to produce shorter, more efficient code, I have created a "chicken and egg" / "catch-22" problem. I can think of several ways to fix this, none of them elegant. I want my code...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.