dbTalk Databases Forums  

dts import excel files procing error: open method of workbooks..fa

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss dts import excel files procing error: open method of workbooks..fa in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Ben
 
Posts: n/a

Default dts import excel files procing error: open method of workbooks..fa - 08-22-2005 , 08:28 AM






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

Reply With Quote
  #2  
Old   
Allan Mitchell
 
Posts: n/a

Default Re: dts import excel files procing error: open method of workbooks..fa - 08-22-2005 , 12:37 PM






If all you want is to loop over the Excel files then why would you need the
Excel object model? What are you trying to do with the Excel spreadsheets?

Allan

"Ben" <ben_1_ AT hotmail DOT com> wrote

Quote:
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



Reply With Quote
  #3  
Old   
Ben
 
Posts: n/a

Default Re: dts import excel files procing error: open method of workbooks - 08-22-2005 , 05:10 PM



im importing their data for use in a sql backend. i left out the import and
parsing code

"Allan Mitchell" wrote:

Quote:
If all you want is to loop over the Excel files then why would you need the
Excel object model? What are you trying to do with the Excel spreadsheets?

Allan

"Ben" <ben_1_ AT hotmail DOT com> wrote in message
news:5CBF6B31-C6DB-4294-8525-2AFD2D154037 (AT) microsoft (DOT) com...
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




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.