Question : Debug Export to Excel and Run Macro

Hi all - gotten this as far as I can and now am stumped.  

Need to export access table to new excel file, then run an excel macro (in a second file) against it, then it would be nice to save that new excel file with a new name (like name & date.xls).

This is as far as I got (thanks to existing EE q's!

Currently seems to come close, but runs macro on file containing the macro vs the newly created excel file.

thanks!
wes

Sub expt()

    Dim pth
    pth = CurrentProject.Path & "S:\IP Census\Staging\IPC_CurrMonth.xls"
    On Error Resume Next
    Kill pth
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "tbl_IPCfinal_04_04 same month", pth, True
    Application.FollowHyperlink pth

    Dim xlApp As Object
    Set xlApp = CreateObject("Excel.Application")
    xlApp.Visible = True
    xlApp.Workbooks.Open ("S:\IP Census\Staging\IPCensusMacro_04_18_06.xls") 'contains macro 07_27_06 to run
    xlApp.Workbooks.Open ("S:\IP Census\Staging\IPC_CurrMonth.xls")
    xlApp.Run "Macro07_27_06"
    xlApp.Quit
    Set xlApp = Nothing

End Sub

Answer : Debug Export to Excel and Run Macro

ok, I took your code and tweaked it. Im using my table called transco


Public Sub expt()

    Dim sSource As String
    Dim pth As String
   
    sSource = "C:\ee\eebk1.xls"
    pth = "C:\ee\fredtrans1.xls"
   
    If Dir$(pth) <> "" Then Kill pth
    FileCopy sSource, pth
    DoCmd.TransferSpreadsheet acExport, , "transco", pth, True

    Dim xlApp As Object
    Set xlApp = CreateObject("Excel.Application")
   
    xlApp.Workbooks.Open pth
   
    xlApp.Worksheets("transco").Activate

'My macro is called Macro 1    
    xlApp.Run "Macro1"

'Save and exit
    xlApp.Save
    xlApp.Workbooks.Close
    xlApp.Quit
   
    Set xlApp = Nothing

'Now view file
    Application.FollowHyperlink pth
End Sub



this is working fine
Random Solutions  
 
programming4us programming4us