Timtropolis
12-29-2004, 06:35 AM
Greetings,
I am having some trouble using the "save as" function in my code (below).
obxls.saveas filename:="C:\Access_databases\Exports\NewRisks.csv"
I am trying to automate the process of saving a xls file to a .csv file and everytime I get to this line of code I get an error message stating:
Runtime error 438, Object doesn't support this property or method.
obxls is dimmed as an object.
I'm a little confused here and was wondering if someone else has experienced this. I've looked in some of the other help items here and have not found
what I need. I've seen examples that look just like mine so I'm assuming I have coded correctly. Any ideas?
TIA,
Tim
Pat Hartman
12-29-2004, 11:11 AM
I'm not sure where you got this code from but it isn't Access VBA. Use the TransferText Method/Action or the OutputTo Method/Action to export a .csv file. If you are not using standard delimiters, you will have to create an output spec so you can control the delimiters. Also, in some cases you will need to export a query rather than a table if you need to control field formats.
Timtropolis
12-29-2004, 11:37 AM
well let me include the code so you can see what i'm doing here. The code is legitimate, all I want to know is how to code for the SAVEAS.
Dim dbs As Database
Dim obxls As Object
Dim boolXL As Boolean
Set dbs = CurrentDb
If fIsFileDIR("C:\Access_databases\Exports\NewRisks.csv") = -1 Then
Kill "C:\Access_databases\Exports\NewRisks.csv"
End If
If fIsAppRunning("Excel") Then
Set obxls = GetObject(, "Excel.Application")
boolXL = False
Else
Set obxls = CreateObject("Excel.Application")
boolXL = True
End If
'obxls.Visible = True
obxls.workbooks.Open filename:="C:\Access_databases\Exports\RiskAssertion_Breakout"
obxls.SaveAs filename:="C:\Access_databases\Exports\NewRisks.csv"
obxls.Quit
Set obxls = Nothing
Hopefully this will help
Pat Hartman
12-29-2004, 06:20 PM
It may be legitimate Excel VBA but it isn't Access VBA. Why don't you define obxls as a specific object type. Then you'll get intellisense help for that object or post the question in an Excel forum where the members will be familiar with the Excel object model.
If you are trying to save a worksheet as a .csv, you can do it in two lines of code with Access VBA. Use the TransferSpreadsheet method to link to the spreadsheet. Then use the TransferText method to create a .csv file from the linked spreadsheet. You won't need to automate Excel.
john471
12-29-2004, 07:04 PM
Following Pat's suggestion of explicitly typing the object and then using intellisense would probably lead you to realise that your statement is trying to save the excel application. You need to save the workbook. If you want to do it this way, set an object reference to the workbook, then
objXLWorkbook.SaveAs FileName:="C:\Access_databases\Exports\NewRisks.csv", FileFormat:=xlCSV
HTH regards
John