views:

482

answers:

2

Hi I am trying to use the following code to export tables from access to excel

I am getting error object does not support property or method at the end

 Set objexcel = New Excel.Application
   objexcel.Visible = True

   If Dir("C:\reports\Data_Analysis1.xls") = "" Then
   objexcel.Workbooks.Add
   Set wbexcel = objexcel.ActiveWorkbook
   Set objSht = wbexcel.Worksheets("Sheet1")
   Else
   Set wbexcel = objexcel.Workbooks.Open("C:\Documents and Settings\TAYYAPP\Desktop\test folder\reports\ERROR REPORT4.xls")
   Set objSht = wbexcel.Worksheets("Sheet1")
   End If

   objSht.Activate


   objexcel.DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "UTYP_Anzahl", "C:\Reports\Data_Analysis1.xls", True
+1  A: 

DoCmd as in "DoCmd.TransferSpreadsheet" is an MS Access command, not an excel command. I think that is your problem.

If this VBA is running inside MS Access then just refer to it as

DoCmd.TransferSpreadsheet

Not

objexcel.DoCmd.TransferSpreadsheet

Also, if that is what you're doing, you don't need to manually create an excel file with Execl Automation, Access will do that for you.

Apologies if I have misunderstood what you're doing, but I think all you need is the TransferSpreadSheet command.

Binary Worrier
thankx that removed teh error but now i am getting error 3011 that jet databank cannot find the table name. i checked and saw that the table is there
tksy
How about marking this answer as correct then, since it answers the question as posted? Also, can you provide more detail. Which version of MS Access? Are you running VB Script in access, or externally and using automation? Thanks
Binary Worrier
well i am using access 2002 and i am running vb in access
tksy
The only thing I can think of is that you're running without that database open. Honestly I've never seen this error. Try posting another question, specifically for that question. Also isolate the problem down to as small a function as possible and post the source for that function.
Binary Worrier
Have you tried exporting to a different file name, that is, one that does not already exist, for example "C:\Reports\Test.xls"?
Remou
hmm ok thanks i ll do that
tksy
A: 

This answer works with the Excel object and can be helpful, as it allows you to automatically format the excel file.

Philippe Grondier