VBA kode i Access til læsning af Excel filer
Jeg har en mindre Access DB, og via VBA ønsker jeg at læse en Excel fil, men inden jeg overhoved kan læse Excel filen får jeg en fejl...."User-defined type not defined" og den peget på "Excel.Application"
Kode i VBA'en er :
Sub read_FileDexia()
Dim xlExcelApp As Excel.Application
Dim xlImportWorkbook As Excel.Workbook
Dim xlManRange As Excel.Range
Dim xlAccRange As Excel.Range
Dim dbsCurrent As DAO.Database
Dim rstImport As DAO.Recordset
Dim strManagersFile, strSheet As String
Dim iTal, iRow As Integer
Dim xlArray() As Variant
Const inFileDir As String = "Z:\Monthly allocation files\2012\2012-"
strManagersFile = inFileDir & "04\"
strFileName = "DKEXA_201204.xls"
strSheet = "DKEXA_201204"
strManagersFile = strManagersFile & strFileName
Set xlExcelApp = New Excel.Application
Set xlImportWorkbook = xlExcelApp.Workbooks.Open(strManagersFile, 0, True)
Set xlManRange = xlImportWorkbook.Worksheets(strSheet).Range("A3")
Set dbsCurrent = CurrentDb
Set rstImport = dbsCurrent.OpenRecordset("tblInvoice", dbOpenTable)
...
End sub