|
我写的一个小工具,在导入多个表格的时候碰到问题了,导入的时候貌似程序找不到表名。只会导入sheet1的内容。主要代码如下:
xlBook.SaveAs FileName:=Application.CurrentProject.Path & "\positions_tmp.xls", FileFormat:=xlNormal, _
ReadOnlyRecommended:=False, CreateBackup:=False
xlBook.Worksheets.Add
xlBook.Worksheets.Add
tmpFile = Application.CurrentProject.Path & "\positions_tmp.xls"
DoCmd.TransferSpreadsheet acImport, , "table1", tmpFile, True, sheet1
DoCmd.TransferSpreadsheet acImport, , "table2", tmpFile, True, sheet2
DoCmd.TransferSpreadsheet acImport, , "table3", tmpFile, True, sheet3
(以上sheet1这种用具体的赋给的表名代替也不行)
或者用下面这种方法也有问题,它导入了三个文件,生成的三张表表名分别为sheet1, sheet2, sheet3. 但是三张表其实导入的内容都是同一个sheet的。
xl.Visible = True
xl.Workbooks.Open "C:\Documents and Settings\e531825\Desktop\positions_tmp.xls"
With xl
With .Workbooks(.Workbooks.Count)
For i = 1 To .Worksheets.Count
WrksheetName = .Worksheets(i).Name
DoCmd.TransferSpreadsheet (acImport), acSpreadsheetTypeExcel97, WrksheetName, "C:\Documents and Settings\e531825\Desktop\positions_tmp.xls"
Next i
End With
End With
Set xl = Nothing |
|