I'm using Microsoft Excel 2003. I've played with this enought and can't figure it out...
Macro code is below. The very first thing my auto run macro does is check to see if a file exists. I'm testing it repeatedly with the file missing so Excel will shutdown (quit).
Each time this code runs I get the following message:
Run-time error '13':
Type mismatch
The way the macro is below I can't get into debug mode - when I click debug the screen flashes up fast and Excel exits. If I comment out Application.DisplayAlerts = False
I can get into debug mode but nothing is highlighted I get put in the editor window half way down my module.
Question 1)
Anyone have any idea what is causing the error and how to get around it (if no file exists I want the macro to end and Excel to close)?
Question 2)
I'm going to run this macro via a scheduled task any thoughts on problems I might have (if any)?
Thanks
Macro code is below. The very first thing my auto run macro does is check to see if a file exists. I'm testing it repeatedly with the file missing so Excel will shutdown (quit).
Each time this code runs I get the following message:
Run-time error '13':
Type mismatch
The way the macro is below I can't get into debug mode - when I click debug the screen flashes up fast and Excel exits. If I comment out Application.DisplayAlerts = False
I can get into debug mode but nothing is highlighted I get put in the editor window half way down my module.
Question 1)
Anyone have any idea what is causing the error and how to get around it (if no file exists I want the macro to end and Excel to close)?
Question 2)
I'm going to run this macro via a scheduled task any thoughts on problems I might have (if any)?
Thanks
Code:
Sub Auto_Run()
' Check and see if a Crystal Report Excel output file exists ????????. This file
' is used to populate the raw data worksheet in this book.
Dim sPath As String
sPath = "C:\Temp\Dougs Files Duns Load\ExcelLoading\CrExportdata.xls"
' Test if directory or file exists
If FileOrDirExists(sPath) Then
MsgBox sPath & " exists!"
Else
Application.DisplayAlerts = False
Application.Quit
End If
...
...
...
End Sub