Please help to call excel subtotal function from powerbuilder application

Anonymous
2015-02-23T09:54:06+00:00

Hi,

Anybody have any idea to call  excel subtotal function   from power builder application.  The following is the code. My code is working fine now . Only I want add   subtotal function instead of SUM function . Please can u help me it would be very appreciate.

I want to add  the code following code with my existing code please help

 Selection.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(2), _

Replace:=True, PageBreaks:=False, SummaryBelowData:=True

My code as given  below

lole_excel = CREATE OLEObject

li_rtn = lole_excel.ConnectToNewObject("excel.application")

IF li_rtn <> 0 THEN

      MessageBox( "Error", 'Error running MS Excel application.')

      DESTROY lole_Excel

      RETURN false

END IF 

ole_excel = CREATE OLEObject

li_rtn = ole_excel.ConnectToNewObject("excel.application")

IF li_rtn  = 0  THEN

l_str_dir = is_filename

li_nextrow = l_lng_rowcnt + 1

li_lastrow = li_nextrow + 1

ole_excel.visible = false

ole_excel.Application.DisplayAlerts = False

ole_excel.WorkBooks.Open(l_str_dir) 

ole_workbook = ole_excel.application.workbooks(1)

ole_worksheet = ole_workbook.worksheets(1)

ole_excel.Application.Visible = True

ole_worksheet.Columns(1).HorizontalAlignment = -4108

ole_worksheet.Columns(5).HorizontalAlignment = -4108

ole_worksheet.Columns(7).HorizontalAlignment = -4108

ole_worksheet.Columns(8).HorizontalAlignment = -4108

ole_worksheet.Columns(9).HorizontalAlignment = -4108

ole_worksheet.Columns(10).HorizontalAlignment = -4108

ole_worksheet.Columns(11).HorizontalAlignment = -4108

ole_worksheet.Columns(9).NumberFormat = "#,##0"

ole_worksheet.Columns(10).NumberFormat = "#,##0"

ole_worksheet.Columns(11).NumberFormat = "£#,##0.00"

ole_worksheet.Range("A1:K1").Select

ole_worksheet.Range("A1:A"+string(li_nextrow)).Font.ColorIndex = 3

ole_worksheet.Range("A1:K1").Font.Bold = True

ole_worksheet.Columns("A:L").EntireColumn.AutoFit

ole_worksheet.Range("A1:K1").HorizontalAlignment = -4108

 li_nextrow =ole_worksheet.usedrange.rows.count

 li_lastrow = li_nextrow+1

ole_worksheet.Range("F"+string(li_lastrow)+":F"+string(li_lastrow)).Formula = "TOTAL"

ole_worksheet.Range("K"+string(li_lastrow)+":K"+string(li_lastrow)).Formula = "=SUM(K1:K"+string(li_nextrow)+")"

ole_worksheet.Range("F"+string(li_lastrow)+":F"+string(li_lastrow)).Font.ColorIndex = 3

ole_worksheet.Range("F"+string(li_lastrow)+":F"+string(li_lastrow)).HorizontalAlignment  = -4108

ole_worksheet.Range("K"+string(li_lastrow)+":K"+string(li_lastrow)).Font.ColorIndex = 3

ole_workbook.SaveAs(l_str_dir, 39 ) ;

ole_workbook.Close() ;

ole_excel.Application.Quit

ole_excel.disconnectobject()

DESTROY ole_excel

End if

With Thanks

Pol

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes
Answer accepted by question author
  1. Anonymous
    2015-02-24T21:35:47+00:00

    Sorry, I don't know PowerBuilder syntax, but from other examples it looks like the arguments should be in parentheses and named arguments are probably not supported so something like

    ole_worksheet.Range("A1:K"+string(li_lastrow)).Subtotal(1,-4157, Array(2),1,0,1) 

    The only bit I'm worred about in that is the Array(2).

    If there's a way in PowerBuilder to make a single element array containing 2 and passing that, that's what's needed.

    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Anonymous
    2015-02-24T00:04:05+00:00

    Before the SaveAs line:

    ole_worksheet.Range("A1:K"+string(li_lastrow)).Subtotal GroupBy:=1, _

            Function:=xlSum, TotalList:=Array(2), _

            Replace:=True, PageBreaks:=False, SummaryBelowData:=True 

    You probably will want to delete the previous 5 lines dealing with the total row.

    0 comments No comments
  2. Anonymous
    2015-02-24T11:33:31+00:00

    Many Thanks for you reply .

    When I am trying to apply the formule , syntax error is coming . May be it  is sybase power builder  Application problem.

    Many thanks Again

    Pol

    0 comments No comments
  3. Anonymous
    2015-02-24T12:21:58+00:00

    Office

    0 comments No comments