Add formula to table using VB6

al4629740 used Ask the Experts™
I am trying to enter a SUM formula to a table in a Microsoft word document using VB6.  Does anyone know the syntax for doing that?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Analyst Assistant
Don't know specifically about VB6 but here's an example of how to do it in VBA, the syntax should be pretty similar.
Dim wdApp As Object
Dim wdDoc As Object
Dim wdTbl As Object
Dim wdCell As Object
Dim wdTblCl As Object
Dim I As Long

    Set wdApp = CreateObject("Word.Application")
    wdApp.Visible = True
    Set wdDoc = wdApp.Documents.Add
    Set wdTbl = wdDoc.Tables.Add(wdDoc.Range(0, 0), 3, 3)
    With wdTbl
        .Borders.OutsideLineStyle = 1 ' wdLineStylesingle
        .Borders.InsideLineStyle = 1 '
        For I = 1 To .Rows.Count - 1
            For Each wdTblCl In .Rows(I).Cells
                wdTblCl.Range.InsertAfter Int(Rnd * 100) + 10
            Next wdTblCl
        Next I

        For Each wdTblCl In .Rows(I).Cells
            wdTblCl.Formula Formula:="=SUM(Above)"
        Next wdTblCl
    End With
    Set wdDoc = Nothing
    Set wdApp = Nothing

Open in new window


I used the following, but to no avail

oTable.Cell(18, 2).Formula Formula:="SUM(Above)"
NorieAnalyst Assistant

You appear to be missing the = before SUM.
 oTable.Cell(18, 2).Formula Formula:="=SUM(Above)"

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial