xl macros in access

Rat1sully

Unhappy Forced codemonkey
Local time
Today, 20:19
Joined
May 15, 2012
Messages
44
I've got a series of macros I've written in excel, is there a way of saving the module so it can be loaded into access and run on a newly created spreadsheet?

I'm currenly looking at something like this where the .ManipulateData is the last macro in the module that runs through the others in order

Code:
 DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qryHeatMapFinal_Crosstab", CurrentProject.Path & "\Output\HeatMap output.xls", True, "HeatMapData"
    
    Dim XLApp As Object
    ' Open the XLS fle, make it visible, get control and run a macro called ManipulateData
    Set XLApp = CreateObject("Excel.Application")
    With XLApp
    .Application.Visible = True
    .UserControl = True
    .workbooks.Open CurrentProject.Path & "\Output\HeatMap output.xls"
    .ManipulateData
    .workbooks.Close
    '.Quit
    .workbooks.Open CurrentProject.Path & "\Output\HeatMap Plot.xls"
    End With
    Set XLApp = Nothing
    
    Kill CurrentProject.Path & "\Output\HeatMap output(Delete ME).xls"
 
Got there in the end, for anyone else who needs to load a module into excel from access to run some macros code as follows

Note. this work to do a load of formatting to a newly created spreadsheet in order to display the data how it's needed for the end user

Code:
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qryHeatMapFinal_Crosstab", CurrentProject.Path & "\Output\HeatMap output.xls", True, "HeatMapData"
    
    Dim XLApp As Object
    ' Open the XLS fle, make it visible, get control and run a macro called AutoOpen
    Set XLApp = CreateObject("Excel.Application")
    With XLApp
    .Application.Visible = False
    .UserControl = True
    .workbooks.Open CurrentProject.Path & "\Output\HeatMap output.xls"
    .VBE.ActiveVBProject.VBComponents.Import CurrentProject.Path & "\Data\HeatmapFormatting.bas"
    .Application.Run "ManipulateData"
    .workbooks.Close
    .Quit
    .Application.Visible = True
    .workbooks.Open CurrentProject.Path & "\Output\HeatMap Plot.xls"
    End With
    Set XLApp = Nothing
    
    Kill CurrentProject.Path & "\Output\HeatMap output(Delete ME).xls"
    Kill CurrentProject.Path & "\Output\HeatMap output.xls"
 

Users who are viewing this thread

Back
Top Bottom