gpt4 book ai didi

excel - 如何让 excel 在执行宏时显示等待消息?

转载 作者:行者123 更新时间:2023-12-04 19:54:01 32 4
gpt4 key购买 nike

我有一个查询数据库的宏(在本例中是一个 excel 工作簿),但是当宏查询数据库时,需要 30 秒,用户认为程序已损坏。我尝试使用“Application.StatusBar =”刷新文件。 “”,但用户看不到句子,最好的方法是使用带有消息“稍等”的消息框,并且当宏完成时,关闭此消息。你帮我写代码吗?我认为解决方案是这样的:

Sub Button1_Click()
'Call msgbox with message "Await a moment"
Dim x As Long
For x = 0 To 2000000000 Step 1
Next
'The msgbox is closed
End Sub

我认为解决方案是 msgbox 但它是另一种选择,继续吧!

最佳答案

Msgbox 不会工作,因为它会停止执行所有操作,直到用户单击“确定”。

如果您在设置后立即放置一个 DoEvents 以便系统有时间更新屏幕,状态栏就会起作用。

您唯一的其他选择是创建一个在处理过程中显示的特殊表单,但在显示它之后您还需要一个 DoEvents

Sub Test()
' create a userform and name it frmWait
' put whatever you want on that form
' that is what will be displayed while the user waits

frmWait.Show vbModeless
DoEvents

' do your processing here

Unload frmWait
End Sub

或者:

Sub Test()
Application.StatusBar = "Refreshing File. "
DoEvents

' do your processing here

' reset the status bar to normal
Application.StatusBar = ""
End Sub

关于excel - 如何让 excel 在执行宏时显示等待消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59495559/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com