CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 1999
    Location
    Somerset, England
    Posts
    20

    Checking for user input in an Excel Macro

    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.


  2. #2
    Join Date
    Feb 2000
    Location
    Indiana
    Posts
    308

    Re: Checking for user input in an Excel Macro

    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





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured