VBA Excel 宏消息框自动关闭

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19008288/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 16:43:10  来源:igfitidea点击:

VBA Excel macro message box auto close

excelvbaexcel-vba

提问by Mike

I've an Excel macro that runs on opening the file, opens another excel file, refreshes the data, saves and then closes it.

我有一个 Excel 宏,它在打开文件时运行,打开另一个 excel 文件,刷新数据,保存然后关闭它。

I also have a middle bit (Dim AckTime) that displays a pop up message for second to show what it's done.

我还有一个中间位(Dim AckTime),它显示第二个弹出消息以显示它已完成的操作。

BUT.. Since I set the macro to run on opening the workbook using Public Sub Workbook_Open() the message box pops up but will not close automatically on 1 second anymore.

但是 .. 由于我将宏设置为在使用 Public Sub Workbook_Open() 打开工作簿时运行,消息框会弹出,但不会在 1 秒后自动关闭。

Can anyone help?

任何人都可以帮忙吗?

Public Sub Workbook_Open()

Application.ScreenUpdating = False Application.DisplayAlerts = False
Application.AskToUpdateLinks = False

     With Workbooks.Open("\filename.xlsm")
         ActiveWorkbook.RefreshAll 'updates the data
         ActiveWorkbook.Sheets("Dashboard").Range("A2").Value = DateTime.Now 
         ' updates this cell with the current time

         Dim AckTime As Integer, InfoBoxWebSearches As Object
         Set InfoBoxWebSearches = CreateObject("WScript.Shell")
         AckTime = 1
         Select Case InfoBoxWebSearches.Popup("Updated, saving & closing...", _
             Case 1, -1
         End Select

         .Save
         .Saved = True 'when saved..
         .Close 0 'close the file

     End With

End Sub

采纳答案by Joe Laviano

Select Case InfoBoxWebSearches.Popup("Updated, saving & closing...", AckTime)

Should be your only error. You just didn't set the wait time.

应该是你唯一的错误。你只是没有设置等待时间。