el_chileno
New Member
- Joined
- Feb 24, 2003
- Messages
- 14
What is the proper syntax for manipulating Excel data from Access 97 (or is it even possible)?
I want to create an Access module that will not only export data, but reformat/manipulate the data in Excel. Here is the first part of the code I have so far:
Function export_forecast()
DoCmd.OutputTo acOutputQuery, "Forecast Maximum", acFormatXLS, , True
Dim xlwbk As Object, xlfile As Object
Set xlfile = GetObject("c:\Forecast Maximum.xls")
Set xlwbk = xlfile.Application.ActiveWorkbook
'Remove decimals
With xlwbk
Columns("E:P").Select
Selection.NumberFormat = "0"
End With
End Sub
When I run this I get a Run-Time Error 1004: Method 'Columns' of object '_Global' failed.
My guess is that xlfile.application.Activeworkbook is not the right syntax, but what do I replace it with? Nothing I have tried so far works.
I have written the VB code in Excel already and even tried to import it to the newly exported file using VBProject.VBComponents.Import but that method gave me an error "Class doesn't support Automation".
Am I going to be able to do this, or should I just export the data from Access and then run the Excel macro? This method is fine if I have to do it, but it would be nice to have it all done within Access.
I want to create an Access module that will not only export data, but reformat/manipulate the data in Excel. Here is the first part of the code I have so far:
Function export_forecast()
DoCmd.OutputTo acOutputQuery, "Forecast Maximum", acFormatXLS, , True
Dim xlwbk As Object, xlfile As Object
Set xlfile = GetObject("c:\Forecast Maximum.xls")
Set xlwbk = xlfile.Application.ActiveWorkbook
'Remove decimals
With xlwbk
Columns("E:P").Select
Selection.NumberFormat = "0"
End With
End Sub
When I run this I get a Run-Time Error 1004: Method 'Columns' of object '_Global' failed.
My guess is that xlfile.application.Activeworkbook is not the right syntax, but what do I replace it with? Nothing I have tried so far works.
I have written the VB code in Excel already and even tried to import it to the newly exported file using VBProject.VBComponents.Import but that method gave me an error "Class doesn't support Automation".
Am I going to be able to do this, or should I just export the data from Access and then run the Excel macro? This method is fine if I have to do it, but it would be nice to have it all done within Access.