My code is using errorcodes generated from Excel. So I don't want to turn off alerts. However I'm having an issue and want to answer the Excel Alert caused by the save error "File already exists, Do you want to save over?" message and want to answer "No". Is this possible? Below is some of my code:
Set oExcelFile = oFileObject.GetFile(strExternalFilePath)
strExcelFileName = oExcelFile.Name
Set oExcelObject = GetObject("","Excel.Application")
Set ExcelWorkbook = oExcelObject.Workbooks.Open(strExternalFilePath)
Set oExcelSheet = ExcelWorkbook.Sheets(1)
On Error resume next
oExcelSheet.parent.save
If Err.Number <> 0 Then
OExcelObject.diplayalerts.Visible = True
msgbox "The file is open and needs to be closed"
subDestroyObjects
wscript.quit
Else
oExcelObject.Application.Windows(strExcelFileName).Visible = True
oExcelObject.Application.Visible = False
End If
End IF
End Sub
Set oExcelFile = oFileObject.GetFile(strExternalFilePath)
strExcelFileName = oExcelFile.Name
Set oExcelObject = GetObject("","Excel.Application")
Set ExcelWorkbook = oExcelObject.Workbooks.Open(strExternalFilePath)
Set oExcelSheet = ExcelWorkbook.Sheets(1)
On Error resume next
oExcelSheet.parent.save
If Err.Number <> 0 Then
OExcelObject.diplayalerts.Visible = True
msgbox "The file is open and needs to be closed"
subDestroyObjects
wscript.quit
Else
oExcelObject.Application.Windows(strExcelFileName).Visible = True
oExcelObject.Application.Visible = False
End If
End IF
End Sub