Hi all,
I've made a new report to generate an Excel workbook and I must add (collapseable) subtotals to 24 columns.
The VBA syntax is quite simple:
Selection.Subtotal GroupBy:=4, Function:=xlSum, TotalList:=Array(8, 10, 12, 14, 16), Replace:=True, PageBreaks:=False, SummaryBelowData:=True
However, I've been unable to create the TotalList array - Navision will only accept one total column argument (e.g. 8 as int). I've searched the forum (and other webs) and I've seen some suggestions like inserting formulas by code into every subtotal field needed. The problem is that by doing so the scheme won't work (a must in this case so the user can collapse the data in this huge file according to the GroupBy field).
I've almost tried every possible syntax (obviously not all because the problem is still there ](*,) . That includes every possible combination of single & double quotes & parenthesis, creating an int array, ehem... even passing a string!! :-$
Does anyone have the solution to translate the VBA syntax into C/AL?
I've even tried with just one column subtotalled and then copy & paste the formula - it almost works - it just pastes it in the wrong cells :oops: probably because I can't pass the Find method with the full parameter list (to pass Search by Column) - it causes an exeption (of course without giving any helpful details...)
To really finish me off, my customer still uses the Excel 8 Library (VBA help not installed) whereas I use 12...
If any of you don't like the idea of a lady going bald (me when the sun comes up in a couple of hours :roll: ) and has a possible solution - please let me know.
Thanks in advance,
B
Comments
The issue is to create an array that is compatible the the Subtotal Function.
I resolved this issue by generating the array using inline VBScript.
In the following code, the VBScript is of type Automation 'Microsoft Script Control 1.0'.ScriptControl
Tested and works successfully.
I was thrilled to find your solution to this problem. I am struggling with a similar problem, and even though I have tried to implement the same solution as yours, I still cant make it work. Maybe you can pinpoint the problem.?
I try to use the Querytable.Add function, but with setting the property: TextFileColumnDataTypes I still get this error :
My code is this:
PS. I use "_" for fielddelimiter in my sourcefile, looking like this in the first line: 01_0400_10_
My aim is to avoid that the leeding zero's are not removed when converting the file to xls.
I hope you can help :-k
I found the solution now on a related post : viewtopic.php?f=23&t=44437&start=0
Thanks Tayamarn!!