热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

ExcelVBA“请等待”弹出消息。-ExcelVBA“PleaseWait”Pop-UpMessage

IamtryingtocreateaPleaseWaitmessageinExcel-VBA.Thisistoremindtheuserprocessingasq

I am trying to create a Please Wait message in Excel-VBA. This is to remind the user processing a sql query that the process is still ongoing.

我正在尝试在Excel-VBA中创建一个请等待消息。这是为了提醒处理sql查询的用户该过程仍在进行。

I would like to have this message displayed in a userform.

我希望这个消息以userform显示。

Currently, the user connects to sql db, selects db and some other options, presses Go... and the form does not unload. At the Go point i have another form which pops up with message Please Wait, but this form does not unload, i.e. the sql execute command does not run.

目前,用户连接到sql db,选择db和其他一些选项,按Go…并且表单没有卸载。在Go point,我有另一个弹出消息的表单,请等待,但是这个表单不卸载,即sql execute命令不运行。

My code for calling the Please Wait userform, including a label:

我调用请等待用户表单的代码,包括一个标签:

   Call WaitShowSQl.ExecuteCall KillWaitCall WaitShow
   SQl.Execute
   Call KillWait

In another code module I have:

在另一个代码模块中:

   Sub WaitShow()
   Wait.Show
   End Sub

   Sub KillWait()
   Unload Wait
   End Sub

I have userform called wait with following code:

我有一个叫wait的userform,代码如下:

Private Sub UserForm_Activate()
Call PleaseWait
End Sub 

Sub PleaseWait()
Wait.Label1.Caption = "Calculating...Please Wait!"
End Sub

Now when executing the code, the run-time does not move back through the module in order to execute the following:

现在,在执行代码时,运行时不会通过模块返回来执行以下操作:

SQl.ExecuteSQl.Execute

I can show the progress of the program with a status bar, but a userform pop up message would be very useful for this program.

我可以使用状态栏显示程序的进度,但是userform弹出消息对这个程序非常有用。

4 个解决方案

#1


6  

The default behavior of the Form.Show method is to show the form as a modal dialog. What you are looking for is a modeless dialog box, so you need to specify that, like this:

表单的默认行为。Show method是将表单显示为模态对话框。您正在寻找的是一个无模型对话框,因此您需要指定这个对话框,如下所示:

Sub WaitShow()
   Wait.Show vbModeLess
End Sub

Update:

更新:

If you can't user a modeless dialog, you have other options, as mentioned in a comment. One of them is to let the wait userform do the SQL executing. This could be done like this:

如果您不能使用无模型对话框,您可以使用其他选项,如注释中所述。其中之一是让等待用户表单执行SQL执行。可以这样做:

In the wait form, first declare variables

在等待表单中,首先声明变量。

Private mySomeParameter1 As String
Private mySomeReturnValue1 As String

'Input parameters to the form
Public Sub Init(ByVal some_parameter1 As String, ...)
... Initialize your SQL, NOT execute it
End Sub

'Output values from the from
Public Sub GetReturns(ByRef some_return_value1 As String, ...)
... set the output parameters...
End Sub

'Do the work
Private Sub UserForm_Activate()
  Call PleaseWait
  'Either call DoEvents or a manual Refresh to let the label display itself
  Call ExecutSQL    ' A function that executes the SQL
  Unload Me
End Sub

And in the main form:

主要形式是:

Sub WaitShow()
   Wait.Init(the parameters...)
   Wait.Show
   Wait.GetReturns(the results...)
End Sub

Yet another option for you would be to skip the Wait form completely and instead show an "Waiting" Image on the mainform and hide it when the SQL processing is done.

另一个选择是完全跳过等待表单,而是在主表单上显示一个“等待”映像,并在SQL处理完成时隐藏它。

#2


1  

Here's how to show a progress bar while your users are waiting for Excel to finish processing:

下面介绍如何在用户等待Excel完成处理时显示进度条:

https://stackoverflow.com/a/10791349/138938

https://stackoverflow.com/a/10791349/138938

Excel progress bar

In your case, you can guess a reasonable "average" time for your queries and have the progress bar update with percentages of that time, which will reassure your users that Excel is working and they don't need to panic.

在您的情况下,您可以为您的查询猜测一个合理的“平均”时间,并使用该时间百分比更新进度条,这将使您的用户放心,Excel正在工作,他们不需要惊慌。

#3


0  

My solution is far less elegant and impressive than the others. FYI, my script is doing processing for a number of partners within a FOR...NEXT loop, and I want to update the screen with the partner currently being processed.

我的解决方案远不如其他方案优雅和令人印象深刻。顺便说一下,我的脚本正在为a for…下一个循环,我想用正在处理的合作伙伴更新屏幕。

I created a worksheet tab called "Messages". I expanded cell A1 as wide and tall as I could, and I picked a font that I liked a color scheme that I liked. My script starts by turning off ScreenUpdating. I then

我创建了一个名为“Messages”的工作表选项卡。我尽可能地扩大单元格A1的宽度和高度,我选择了一种我喜欢的颜色方案。我的脚本从关闭屏幕更新开始。然后我

Sheets("Messages").Select
Cells(1, 1).Value = "Processing " & Partner
Application.ScreenUpdating = True
Application.ScreenUpdating = False

After this, I return to whatever sheet I need. Nothing fancy, but it's fast, easy, and does what I need. :)

在这之后,我回到我需要的任何表格。没有什么奇特的,但它又快又容易,而且是我所需要的。:)

#4


0  

I use a command button on the form set to a very small size, hidden when the form loads, with the caption "Please wait, processing..."

我在设置为很小的表单上使用命令按钮,当表单加载时隐藏该按钮,标题为“请等待,处理……”

I resize the button in the form Iniliatlise event (I simply resize to the form size using the top, left, width & height properties). YOu can of course make it whatever size you like.

我在表单Iniliatlise事件中调整按钮的大小(我只是使用顶部、左侧、宽度和高度属性调整到窗体大小)。你当然可以做任何你喜欢的尺寸。

I make the command button visible just before my time consuming code & make it hidden again at the end of the code.

我使命令按钮在我耗时的代码之前可见,并使它再次隐藏在代码的末尾。

Requires some "DoEvents", but works perfectly.

需要一些“DoEvents”,但效果很好。


推荐阅读
  • 前景:当UI一个查询条件为多项选择,或录入多个条件的时候,比如查询所有名称里面包含以下动态条件,需要模糊查询里面每一项时比如是这样一个数组条件:newstring[]{兴业银行, ... [详细]
  • 本文介绍了一个在线急等问题解决方法,即如何统计数据库中某个字段下的所有数据,并将结果显示在文本框里。作者提到了自己是一个菜鸟,希望能够得到帮助。作者使用的是ACCESS数据库,并且给出了一个例子,希望得到的结果是560。作者还提到自己已经尝试了使用"select sum(字段2) from 表名"的语句,得到的结果是650,但不知道如何得到560。希望能够得到解决方案。 ... [详细]
  • 解决.net项目中未注册“microsoft.ACE.oledb.12.0”提供程序的方法
    在开发.net项目中,通过microsoft.ACE.oledb读取excel文件信息时,报错“未在本地计算机上注册“microsoft.ACE.oledb.12.0”提供程序”。本文提供了解决这个问题的方法,包括错误描述和代码示例。通过注册提供程序和修改连接字符串,可以成功读取excel文件信息。 ... [详细]
  • Spring源码解密之默认标签的解析方式分析
    本文分析了Spring源码解密中默认标签的解析方式。通过对命名空间的判断,区分默认命名空间和自定义命名空间,并采用不同的解析方式。其中,bean标签的解析最为复杂和重要。 ... [详细]
  • 本文介绍了如何使用php限制数据库插入的条数并显示每次插入数据库之间的数据数目,以及避免重复提交的方法。同时还介绍了如何限制某一个数据库用户的并发连接数,以及设置数据库的连接数和连接超时时间的方法。最后提供了一些关于浏览器在线用户数和数据库连接数量比例的参考值。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • Java String与StringBuffer的区别及其应用场景
    本文主要介绍了Java中String和StringBuffer的区别,String是不可变的,而StringBuffer是可变的。StringBuffer在进行字符串处理时不生成新的对象,内存使用上要优于String类。因此,在需要频繁对字符串进行修改的情况下,使用StringBuffer更加适合。同时,文章还介绍了String和StringBuffer的应用场景。 ... [详细]
  • 本文详细介绍了在ASP.NET中获取插入记录的ID的几种方法,包括使用SCOPE_IDENTITY()和IDENT_CURRENT()函数,以及通过ExecuteReader方法执行SQL语句获取ID的步骤。同时,还提供了使用这些方法的示例代码和注意事项。对于需要获取表中最后一个插入操作所产生的ID或马上使用刚插入的新记录ID的开发者来说,本文提供了一些有用的技巧和建议。 ... [详细]
  • 本文详细介绍了Spring的JdbcTemplate的使用方法,包括执行存储过程、存储函数的call()方法,执行任何SQL语句的execute()方法,单个更新和批量更新的update()和batchUpdate()方法,以及单查和列表查询的query()和queryForXXX()方法。提供了经过测试的API供使用。 ... [详细]
  • 高质量SQL书写的30条建议
    本文提供了30条关于优化SQL的建议,包括避免使用select *,使用具体字段,以及使用limit 1等。这些建议是基于实际开发经验总结出来的,旨在帮助读者优化SQL查询。 ... [详细]
  • Go Cobra命令行工具入门教程
    本文介绍了Go语言实现的命令行工具Cobra的基本概念、安装方法和入门实践。Cobra被广泛应用于各种项目中,如Kubernetes、Hugo和Github CLI等。通过使用Cobra,我们可以快速创建命令行工具,适用于写测试脚本和各种服务的Admin CLI。文章还通过一个简单的demo演示了Cobra的使用方法。 ... [详细]
  • 本文介绍了iOS数据库Sqlite的SQL语句分类和常见约束关键字。SQL语句分为DDL、DML和DQL三种类型,其中DDL语句用于定义、删除和修改数据表,关键字包括create、drop和alter。常见约束关键字包括if not exists、if exists、primary key、autoincrement、not null和default。此外,还介绍了常见的数据库数据类型,包括integer、text和real。 ... [详细]
  • 本文详细介绍了如何使用MySQL来显示SQL语句的执行时间,并通过MySQL Query Profiler获取CPU和内存使用量以及系统锁和表锁的时间。同时介绍了效能分析的三种方法:瓶颈分析、工作负载分析和基于比率的分析。 ... [详细]
  • 本文讨论了在使用sp_msforeachdb执行动态SQL命令时,当发生错误时如何捕获数据库名称。提供了两种解决方案,并介绍了如何正确使用'?'来显示数据库名称。 ... [详细]
  • 本文介绍了Swing组件的用法,重点讲解了图标接口的定义和创建方法。图标接口用来将图标与各种组件相关联,可以是简单的绘画或使用磁盘上的GIF格式图像。文章详细介绍了图标接口的属性和绘制方法,并给出了一个菱形图标的实现示例。该示例可以配置图标的尺寸、颜色和填充状态。 ... [详细]
author-avatar
Lyceenne
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有