LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ben Ben is offline
external usenet poster
 
Posts: 13
Default Open method of worksbooks class failed

I am trying to read all excel files in a directory, and the code that opens
the files is pasted below. When i run the code some excel spreadsheets open
while others give me the error: "open method of workbooks class failed"

I have narrowed the problem down to the fact that when i manually open the
files that "fail" i get a message saying Microsft Excel has made repairs to
the spread sheet: "Renamed invalid sheet name". if i save this new sheet, it
opens fine with the below code.

My question is, how can i get the code to open, "ok" the repairs, close and
save the spreadsheet then open it again to be read? I am trying to automate
this whole process where these sheets are being created by one process and
this second process is importing them into sql server. This needs to be
completely automated.

Thanks for any and all help!
Ben

--code to open excel files....specifics on reading/parsing file have been
removed for security reasons --

For Each fsoFile in fsoFolder.Files
'Check for proper file extension
If LCase(Right(fsoFile.Name, 4)) = ".xls" Then

'Create the full file name
sFileName = sFolderImport & fsoFile.Name
DTSGlobalVariables("FileName").Value = sFileName

'Excel file object
dim objExcel

Set objExcel = CreateObject("Excel.Application")
objExcel.DisplayAlerts = true

'Excel workbook object
dim objWorkbook
objExcel.Visible = True

'Set objWorkbook = objExcel.Open (sFileName)

objExcel.Workbooks.open sFileName
set objWorkbook = objExcel.ActiveWorkbook.Worksheets(1)
msgBox (sFileName & " has been opened")

'Save any changes
objExcel.Save

'Close the file and excel
objExcel.Quit

End If
Next
 
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
Autofill method of range class failed Don Guillett Excel Discussion (Misc queries) 0 February 27th 08 03:56 PM
Autofill method of range class failed - sometimes Intellihome Excel Programming 9 May 28th 05 01:21 PM
Insert method of range class failed quartz[_2_] Excel Programming 0 August 17th 04 07:31 PM
Insert method of range class failed DJH Excel Programming 0 August 17th 04 07:30 PM
Open Method of workbooks class failed kiran[_2_] Excel Programming 0 November 6th 03 09:58 PM


All times are GMT +1. The time now is 06:51 AM.

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"