Thanks for the suggestions.
JosephP, I had a look at the link and at some pages linked to that to try to get my head around application event monitoring, but alas, I fear it is a bridge too far for me at the moment. I didn't understand what I was reading.
JieJenn, I originally couldn't get your idea to work, as Personal.xls runs before the Temp workbook has opened. However, in trying to get my head around JosephP's idea, I came across OnTime, which allowed me to delay the execution of Personal.xls until the Temp file had opened.
In the ThisWorkbook module:
Private Sub Workbook_Open() 'This automatically runs when Personal.xls opens.
Call Application.OnTime((Now + 1 / 86400), "AutoRunSetup") ' Waits 1 second (60x60x24=86400)then tries to run AutoRunSetup.
End Sub
In the main module (I had to use a wildcard in the Temp file name, and use "Like", as the file name has a random number in it each time):
Sub AutoRunSetup()
Dim str As String
On Error GoTo WaitMore: ' Next line generates an error if the Temp file is not yet open.
str = "Case%20Advanced%20Find%20View * .xls" 'This is the Temp file.
If ActiveWorkbook.Name Like str Then Call FillSheet 'If the Temp file is open, and is now the active workbook, continue with other code.
GoTo Finish:
WaitMore:
Run Workbook_Open 'If an error occurred (the temp file is not yet open), go back to the Sub that opens AutoRunSetup and wait another second.
Finish:
End Sub
I'd be interested to know what you think of this. Can it be improved?
Bookmarks