Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-26-2022, 06:28 AM
BrianHoard BrianHoard is offline How to show wait cursor during vba script? Windows 10 How to show wait cursor during vba script? Office 2019
Advanced Beginner
How to show wait cursor during vba script?
 
Join Date: Jul 2022
Location: Haymarket, VA USA
Posts: 85
BrianHoard is on a distinguished road
Default How to show wait cursor during vba script?

I have some scripts that may take 30 seconds to run on large documents, so I want to show the hourglass/wait cursor.


I'm using the following code, but it doesn't have any effect. The cursor flashes rapidly back and forth between normal and wait. The same behavior if I comment this out. Am I missing some step to make this work?

Code:
' Set status bar text
StatusBar = ("Please wait...")

' Turn cursor to wait
System.Cursor = wdCursorWait
DoEvents

' My script runs here...

' Turn cursor back to normal.
StatusBar = ("Complete")
System.Cursor = wdCursorNormal
Reply With Quote
  #2  
Old 08-26-2022, 04:13 PM
rollis13's Avatar
rollis13 rollis13 is offline How to show wait cursor during vba script? Windows 10 How to show wait cursor during vba script? Office 2016
Competent Performer
 
Join Date: Jan 2021
Location: Cordenons
Posts: 140
rollis13 will become famous soon enough
Default

Here is how I managed to see the wdCursorWait:
Code:
Option Explicit
Sub test()
    Dim a
    ' Set status bar text
    StatusBar = ("Please wait...")
    ' Turn cursor to wait
    ' My script runs here...
    For a = 1 To 2000
        System.Cursor = wdCursorWait              '<- here
        Selection.TypeText Text:="1"
    Next a
    ' Turn cursor back to normal.
    StatusBar = ("Complete")
    System.Cursor = wdCursorNormal
End Sub
Reply With Quote
  #3  
Old 08-26-2022, 04:59 PM
BrianHoard BrianHoard is offline How to show wait cursor during vba script? Windows 10 How to show wait cursor during vba script? Office 2019
Advanced Beginner
How to show wait cursor during vba script?
 
Join Date: Jul 2022
Location: Haymarket, VA USA
Posts: 85
BrianHoard is on a distinguished road
Default

hmmm. I tried your code, and it showed the wait cursor for a while, adding "1"'s to the document, then the cursor went back to normal, and more "1"s were added for another 10 seconds or so.


Makes me wonder if you are saying the wait cursor can only be done inside of a For loop?
Reply With Quote
  #4  
Old 08-26-2022, 11:35 PM
rollis13's Avatar
rollis13 rollis13 is offline How to show wait cursor during vba script? Windows 10 How to show wait cursor during vba script? Office 2016
Competent Performer
 
Join Date: Jan 2021
Location: Cordenons
Posts: 140
rollis13 will become famous soon enough
Default

Sorry, did some other testing, the 'wdCursorWait' that shows up is not the function in the macro but the default cursor used by Excel to show that it's working. So, what I said in my previous post is nonsense. This will show wait cursor too.
Code:
Sub test()
    Dim a
    ' Set status bar text
    StatusBar = ("Please wait...")
    ' Turn cursor to wait
    'System.Cursor = wdCursorWait                  '<- here (note that it isn't active)
    ' My script runs here...
    Do While a < 2001
        For a = 1 To 2000
            Selection.TypeText Text:="abc"
        Next a
    Loop
    ' Turn cursor back to normal.
    StatusBar = ("Complete")
    System.Cursor = wdCursorNormal
End Sub
Reply With Quote
  #5  
Old 08-27-2022, 08:08 AM
BrianHoard BrianHoard is offline How to show wait cursor during vba script? Windows 10 How to show wait cursor during vba script? Office 2019
Advanced Beginner
How to show wait cursor during vba script?
 
Join Date: Jul 2022
Location: Haymarket, VA USA
Posts: 85
BrianHoard is on a distinguished road
Default

Still getting similar results with this. The cursor goes to wait as letters are added to the document. Then the cursor goes to normal and more letters are added.

I've worked in other programs where I could simply tell the cursor to be what I wanted, and it behaved exactly as expected. I'm not sure how this one in Word is supposed to behave. As in the other programs, if you forgot to tell it to go back to normal, you'd be left with the wait cursor after your script exited. But here it feels like VBA's cursor command is being overwritten by Windows or something.

Which makes me wonder if a better way would be to figure out how to call the Windows cursor command somehow rather than do it inside of Word. Since this one doesn't seem to act right. But this is all new to me, so I know I have much to learn.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cursor/typing caret doesn't show when moved around in Word 2019 vkhu Word 2 09-30-2020 07:58 AM
Wait (hourglass) cursor constantly flashing after loading large file didlinghill Word 4 01-26-2015 06:08 AM
How to show wait cursor during vba script? Wait for 2013? Warranty issue.... alexb123 Office 1 12-14-2012 01:44 PM
How to show wait cursor during vba script? Applicatin.wait SDondeti Word VBA 1 05-27-2011 02:12 AM
Show cursor in PP presentations whs PowerPoint 0 03-12-2011 11:31 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:01 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft