tag:blogger.com,1999:blog-7176045.post111330339488850861..comments2007-03-02T18:29:32.946+03:00Comments on Alex & Access: How to import password-protected excel spreadsheet...Alex Dybenkohttp://www.blogger.com/profile/16954512620659022712noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-7176045.post-1144988439571069142006-04-14T08:20:00.000+04:002006-04-14T08:20:00.000+04:002006-04-14T08:20:00.000+04:00Hi,i would try the following - make a new dummy ex...Hi,<BR/>i would try the following - make a new dummy excel file, a new dummy table to import this excel file, and them after your DoCmd.TransferSpreadsheet each time import this dummy excel file.<BR/>Seems like Access/Excel holds some reference to last imported file, so it does not allow to close excel<BR/>Also you can try to import dummy text file.Alex Dybenkohttp://www.blogger.com/profile/16954512620659022712noreply@blogger.comtag:blogger.com,1999:blog-7176045.post-1144958237240322572006-04-13T23:57:00.000+04:002006-04-13T23:57:00.000+04:002006-04-13T23:57:00.000+04:00The errors differ. Sometimes Access crashes with a...The errors differ. Sometimes Access crashes with a Runtime error. Other times it says that a particular file is being reserved. After doing some more digging, it seems that the problem stems from this part of the code:<BR/><BR/> oExcel.Quit<BR/> Set oExcel = Nothing<BR/><BR/>Excel never seems to shut down afterwards. If I go into Task Manager and kill any excel.exe processes, then the macro works.<BR/>Otherwise the files seem to remain locked in memory and the macro fails.<BR/><BR/>Thanks again for your help.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-7176045.post-1144956113855228072006-04-13T23:21:00.000+04:002006-04-13T23:21:00.000+04:002006-04-13T23:21:00.000+04:00Hi,and what error you get when it does not work?Hi,<BR/>and what error you get when it does not work?Alex Dybenkohttp://www.blogger.com/profile/16954512620659022712noreply@blogger.comtag:blogger.com,1999:blog-7176045.post-1144955240552923772006-04-13T23:07:00.000+04:002006-04-13T23:07:00.000+04:002006-04-13T23:07:00.000+04:00Hi,I found this on google as well and it was a hug...Hi,<BR/><BR/>I found this on google as well and it was a huge help. I needed to modify it to create a loop that opens and import ranges from a series of spreadsheets. The problem is that some times the code works and other times it doesn't. Can you understand why? The problem seems to be with passing in the password string. Something it works and other times it does not. I appreciate any advice that you can give.<BR/><BR/>Sub CompSheetsEurope_Extract()<BR/><BR/>On Error GoTo CompSheetsEurope_Extract_Err<BR/><BR/><BR/> Dim recFilePaths As Variant, varFileName As Variant<BR/> Dim strPassword As String<BR/> Dim db As Database<BR/> Dim oExcel As Object, oWb As Object<BR/> <BR/> Set oExcel = CreateObject("Excel.Application")<BR/><BR/> DoCmd.SetWarnings False<BR/> <BR/> Set db = CurrentDb()<BR/> Set recFilePaths = db.OpenRecordset("tblCompSheetsEurope")<BR/> <BR/> strPassword = "comp"<BR/> <BR/> DoCmd.RunSQL "DELETE * FROM [tblSalesActualsQuotas] WHERE [LOB] = 'Europe'"<BR/> <BR/> recFilePaths.MoveFirst<BR/> <BR/> Do<BR/> varFileName = recFilePaths![FilePathName]<BR/> <BR/> Set oWb = oExcel.Workbooks.Open(Filename:=varFileName, ReadOnly:=True, Password:=strPassword, _<BR/> UpdateLinks:=0, IgnoreReadOnlyRecommended:=True)<BR/> DoCmd.TransferSpreadsheet acImport, 8, "tblSalesActualsQuotas", _<BR/> varFileName, True, "SalesReport"<BR/> recFilePaths.MoveNext<BR/> oWb.Close SaveChanges:=False<BR/> Loop While Not recFilePaths.EOF<BR/> <BR/> DoCmd.RunSQL "DELETE * FROM [tblSalesActualsQuotas] WHERE ([Actuals] = 0) AND ([Quotas] = 0"<BR/> <BR/> DoCmd.SetWarnings True<BR/> <BR/>CompSheetsEurope_Extract_Exit:<BR/> recFilePaths.Close<BR/> oExcel.Quit<BR/> Set oExcel = Nothing<BR/><BR/> Exit Sub<BR/><BR/>CompSheetsEurope_Extract_Err:<BR/> MsgBox Error$<BR/> Resume CompSheetsEurope_Extract_Exit<BR/><BR/>End SubAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-7176045.post-1113931749831966182005-04-19T21:29:00.000+04:002005-04-19T21:29:00.000+04:002005-04-19T21:29:00.000+04:00Hi,I just found this on google. Thank you so much....Hi,<BR/><BR/>I just found this on google. Thank you so much. It was really helpful. I made a few changes to accomodate the specific worksheet and range.<BR/><BR/><B><BR/>Public Sub ImportProtected(strFile As String, _<BR/>strPassword As String)<BR/>Dim oExcel As Object, oWb As Object<BR/>Set oExcel = CreateObject("Excel.Application")<BR/>Set oWb = oExcel.Workbooks.Open(FileName:=strFile, _<BR/>Password:=strPassword)<BR/><BR/>DoCmd.TransferSpreadsheet transfertype:=acImport, SpreadsheetType:=5, _<BR/> tablename:="tmpTableName", FileName:=strFile, _<BR/> Hasfieldnames:=True, Range:="Q1!C:G"<BR/><BR/>oWb.Close SaveChanges:=False<BR/>oExcel.Quit<BR/>Set oExcel = Nothing<BR/>End Sub<BR/><BR/></B><BR/><BR/>Thanks Again!Faruquenoreply@blogger.com