PDA

View Full Version : Solved: Exporting from Access to Excel Formatting



akn112
03-05-2007, 09:42 AM
Hi all,

I want run an excel macro from my access database through a access macro. To do this i created a module and input the code below (found through yahoo search). What the (access) macro does is its supposed to
1)run a query
2)export it to an excel file (success) and
3)run the module(below)
4)which runs the excel macro.

For step 3, i tried using the OpenModule command in the macros but it didnt work. When i try to use RunCode, it doesnt recognize any code in my module.:help Forgot to mention, the macro is located on a spreadsheet called personal.xls which opens everytime excel opens (reason for opening 2 xls files).



Sub XLTest()
Dim XL as Object
Set XL = CreateObject("Excel.Application")
XL.Workbooks.Open "C:\My Documents\Macros.xls"
XL.Workbooks.Open "C:\My Documents\ExcelFile.xls"
' If there is more than one macro called TestMacro,
' the module name would be required as in
' XL.Run "Module1.TestMacro"
' to differentiate which routine is being called.
XL.Run "Macros.xls!TestMacro"
End Sub


Thanks!

stanl
03-05-2007, 02:10 PM
Maybe I'm confused, but if the macro is in personal.xls shouldn't


XL.Run "Macros.xls!TestMacro"

be


XL.Run "personal.xls!TestMacro" :dunno Stan

akn112
03-06-2007, 05:43 AM
hey, its just the template i used for my macro. I got it to work by creating another module that calls the sub (not sure why access does it that way?) but now im stuck because when i use the output to function, i always need the path and file to already exist. Is there a way to create a new folder/file?