简体   繁体   中英

VBA Excel macro message box auto close

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

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

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.

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
Select Case InfoBoxWebSearches.Popup("Updated, saving & closing...", AckTime)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM