![]() |
prevent open invalid Excel file
Hello,
I am new in Excel object model. I am writing VBScript to open Excel file. The following is a segment of my codes: Set objExcelApp = CreateObject("Excel.Application") 'Open Excel file Set objExcelWorkbook = objExcelApp.Workbooks.Open(pstrExcelFilename) ' If IsNull (objExcelWorkbook) Then objExcelApp.Quit Set objExcelWorkbook = Nothing Set objExcelApp = Nothing vfValidateABRUploadExcel = cintErrorOpenExcelFile Exit Function End If 'Set the active worksheet Set objExcelWorksheet = objExcelWorkbook.Sheets(cintExcelWorkSheetNo) objExcelWorksheet.Activate If the Excel file is invalid format (even file extension is XLS), it will throw exception at the "objExcelApp.Workbooks.Open(pstrExcelFilename) " statement (that is, the program cannot run to "IsNull (objExcelWorkbook)" line). May I know how to prevent open invalid format Excel file? Or, how do I catch the exception that throws at "objExcelApp.Workbooks.Open(pstrExcelFilename) " statement? Thanks a lot. Sa |
prevent open invalid Excel file
I believe VB script support On Error Resume Next
Set objExcelApp = CreateObject("Excel.Application") 'Open Excel file On Error Resume Next Set objExcelWorkbook = objExcelApp.Workbooks.Open(pstrExcelFilename) ' On Error goto 0 if objExcelWorkbook is Nothing then -- Regards, Tom Ogilvy "Sa" wrote in message ... Hello, I am new in Excel object model. I am writing VBScript to open Excel file. The following is a segment of my codes: Set objExcelApp = CreateObject("Excel.Application") 'Open Excel file Set objExcelWorkbook = objExcelApp.Workbooks.Open(pstrExcelFilename) ' If IsNull (objExcelWorkbook) Then objExcelApp.Quit Set objExcelWorkbook = Nothing Set objExcelApp = Nothing vfValidateABRUploadExcel = cintErrorOpenExcelFile Exit Function End If 'Set the active worksheet Set objExcelWorksheet = objExcelWorkbook.Sheets(cintExcelWorkSheetNo) objExcelWorksheet.Activate If the Excel file is invalid format (even file extension is XLS), it will throw exception at the "objExcelApp.Workbooks.Open(pstrExcelFilename) " statement (that is, the program cannot run to "IsNull (objExcelWorkbook)" line). May I know how to prevent open invalid format Excel file? Or, how do I catch the exception that throws at "objExcelApp.Workbooks.Open(pstrExcelFilename) " statement? Thanks a lot. Sa |
prevent open invalid Excel file
"Tom Ogilvy" wrote in message ... I believe VB script support On Error Resume Next It certainly does. |
prevent open invalid Excel file
Pretty sure means I am positive it does, but I am too lazy to actually
confirm it. (referring to Scripting and not VBA). Thanks for the confirmation. <g -- Regards, Tom Ogilvy "Bob Phillips" wrote in message ... "Tom Ogilvy" wrote in message ... I believe VB script support On Error Resume Next It certainly does. |
prevent open invalid Excel file
I just checked my delete temp folder startup script which has that code in
it <g Bob "Tom Ogilvy" wrote in message ... Pretty sure means I am positive it does, but I am too lazy to actually confirm it. (referring to Scripting and not VBA). Thanks for the confirmation. <g -- Regards, Tom Ogilvy "Bob Phillips" wrote in message ... "Tom Ogilvy" wrote in message ... I believe VB script support On Error Resume Next It certainly does. |
All times are GMT +1. The time now is 08:32 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com