Nil Jay
Nil Jay

Reputation: 35

DAO.TableDef not defined in excel

I am trying to convert to to five formats but when i execute the code on line 2 it says DAO.TableDef is not defined. If the code would run succesfully it would create five formats: csv,xml.laccdb, acccdb, xls. The following programs is going to be created as new files in excel vba.

Sub exportTables2XLS()
Dim td As DAO.TableDef, db As DAO.Database
Dim out_file As String
out_file = CurrentProject.Path & "\test.xls"
Set db = CurrentDb()
For Each td In db.TableDefs
If Left(td.Name, 4) = "MSys" Then
'//do nothing -- skip
Else
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _
td.Name, out_file, True, Replace(td.Name, "dbo_", "")
End If
Next
End Sub
'expeced ouput :test.xls, test.xml, test.csv, test.accdb,test.laccdb,

Upvotes: 0

Views: 773

Answers (1)

Pants
Pants

Reputation: 679

If its failing on your definition of the DAO.TableDef, then its probably your References

Alt + F11 > Tools > References

Make sure this is checked, where x is your specific version number: Microsoft DAO x.x Object Library

https://stackoverflow.com/a/13919392/4731063

Upvotes: 3

Related Questions