Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Sa Sa is offline
external usenet poster
 
Posts: 1
Default 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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default prevent open invalid Excel file



"Tom Ogilvy" wrote in message
...
I believe VB script support On Error Resume Next


It certainly does.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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.




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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.






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I prevent Excel trying to open a non-existing file at start Jesperfect Excel Discussion (Misc queries) 0 May 15th 09 01:11 PM
Prevent reviewing toolbar from coming up when I open a file? _justbob49 Excel Discussion (Misc queries) 1 December 21st 07 03:25 PM
cannot open excel file - says invalid file format - what to do? excelless diane Excel Discussion (Misc queries) 2 November 8th 06 03:13 AM
Prevent Access To already open file ashtod1 New Users to Excel 0 January 5th 06 10:57 PM
How to prevent my Macro from opening up another Excel App when I open any other excel file Peter[_50_] Excel Programming 1 November 12th 04 06:05 PM


All times are GMT +1. The time now is 02:34 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"