J
Jim Sagris
I created a query in Access that I need to export to excel. I have found I can do this through the output to action, and it works fine. The problem is once I have the query in excel I want some excel macros to run the minute excel opens. I know how to do this for an existing file, but the problem is when you output to excel it copies over the old file, thereby erasing the pre-loaded macros I had in there.
My solution was that as the data was being exported, I opened a different excel workbook, and then copied the data just exported into this workbook, where the macros could then run. I am running into problems getting the sheet to copy over though, as the commands that usually do that in excel vb I am getting errors for here. Here is the code I was using:
Public Function test()
Dim objXL As Object, x
Set objXL = CreateObject("Excel.Application")
With objXL.Application
.Visible = True
.Workbooks.Open "C:\Documents and Settings\p0007617\My Documents\testing.xls"
.Worksheets("List").Copy
.Workbooks.Open "C:\Documents and Settings\p0007617\My Documents\Book2.xls"
.Worksheets("Destination").Activate
.Activesheet.Paste Destination:= _
.Worksheet("Destination")
End With
end function
It won't recognize the .Activesheet command. I got stuck here and couldnt figure out how to circumvent this problem. Any help would be appreciated.
Jim
My solution was that as the data was being exported, I opened a different excel workbook, and then copied the data just exported into this workbook, where the macros could then run. I am running into problems getting the sheet to copy over though, as the commands that usually do that in excel vb I am getting errors for here. Here is the code I was using:
Public Function test()
Dim objXL As Object, x
Set objXL = CreateObject("Excel.Application")
With objXL.Application
.Visible = True
.Workbooks.Open "C:\Documents and Settings\p0007617\My Documents\testing.xls"
.Worksheets("List").Copy
.Workbooks.Open "C:\Documents and Settings\p0007617\My Documents\Book2.xls"
.Worksheets("Destination").Activate
.Activesheet.Paste Destination:= _
.Worksheet("Destination")
End With
end function
It won't recognize the .Activesheet command. I got stuck here and couldnt figure out how to circumvent this problem. Any help would be appreciated.
Jim