Click to See Complete Forum and Search --> : Checking for user input in an Excel Macro


Londo Molari
February 22nd, 2000, 10:18 AM
I want to be able to check to see if a user has pressed a 'Stop' button
when I am running a query using VBA and populating an Excel Spreadsheet.

Excel seems to hang up whilst I'm in the macro.

Is there any sort of functionality that allows this type of thing?

Regards,

James.

Kyle Burns
February 22nd, 2000, 11:05 AM
If your code takes a long time to run, you can place DoEvents at places in your code to return control to the system and allow messages to process.

Dim bQuitNow as Boolean

Sub MyLongRunningSub()
bQuitNow = false 'Initialize bQuitNow
'Do some actions that take a long time
DoEvents
If bQuitNow = true then
'Clean Up and get Out
End If
'Do some more things
DoEvents
If bQuitNow = true then
'Clean Up and get Out
End If
'etc...
End Sub

private Sub cmdStop_Click()
bQuitNow = true
End Sub