Export Table in Excel and add sum of columns

Gringo

New member
Local time
Today, 10:16
Joined
Sep 14, 2010
Messages
1
Hello,

I have a problem that I am not able to resolve. I have a table which I want to export to Excel. That' Ok, no problem with that.
What I would like to do is add the sum of different columns to my exportation and I haven't figured out how to do it.
Here is my code

Code:
cnConnect.Execute ("Select * Into Tempo From TableCPG Where No_Client = " & NoClient)
sNom = cnConnect.Execute("Select Nom_Client From Tempo").Collect(0)
DoCmd.OutputTo acOutputTable, "Tempo", acFormatXLSX, sPath & Year(datedeproduction) & "\" & sMois & "\" & sNom & ".xlsx"

This is working, but I don't know how to add the sum in there.

I need your help.

Thanks!

Gringo
 
What you will need to do is get Access to Open the workbook and do something like this:

First Set the Reference is Access to use Excel Code, to do this use Alt + F11 on the keyboard then go to Tools and References, then search down until you find Microsoft Excel with a number object library and click the box.

then you need to insert a module and copy and paste the following but will have to adjust it.

Sub UWRexport()
Dim xlapp As Excel.Application
Dim lngstart As Long
Set xlapp = CreateObject("Excel.Application")
With xlapp
.Workbooks.Open "Enter the file path and name.xls"
.Sheets ("Which sheet to select")
.Range ("Which cell to goto")
.Visible = True
End With
xlapp.Range("B7").Select
lngstart = xlapp.ActiveCell.Row
xlapp.ActiveCell.End(xlDown).Select
xlapp.ActiveCell.Offset(1, 0).Select
xlapp.ActiveCell.FormulaR1C1 = "=SUM(R[-" & xlapp.ActiveCell.Row - lngstart & "]C:R[-1]C)"
xlapp.ActiveCell.Font.Bold = True

End Sub
 

Users who are viewing this thread

Back
Top Bottom