I have an Excel macro that I would like to run automatically when the file is opened. The only way I have gotten this to work is by adding a msgbox
before calling to my subroutines. However, this requires me to click OK or close the box for the macros to run. I have tried using a timed msgbox
sub, but this also does not work.
For some reason, the msgbox
pops up before Excel is fully opened, at which point the macro gets stuck here (code for this is below). From here, I tried waiting for the file itself to be opened until it is in write-mode (Workbook.ReadOnly = false
). This also did not work.
Public Sub msgBoxTimer()
Const timeout = 2
Dim objShell As Object
Set objShell = CreateObject("WScript.Shell")
objShell.Popup "Measurement will begin shortly", timeout
End Sub
Private Sub Workbook_Open()
Call msgBoxTimer
Call init ' initiate device
Call updateIndex ' collect & record measurements
End Sub