InsertFormula 公式:="=SUM(ABOVE)"

InsertFormula Formula:="=SUM(ABOVE)"

我目前正在阅读 excel table 并使用 excel table 中的匹配记录生成 MS-word 表格。我已经完成了 88%,但是我在将公式插入单元格时遇到了问题。

LastProdHistRow = LastProdHistRow + 6               ' Adding additional rows to production history table
Set rRange = objDoc.Bookmarks(BkProdHist).Range
Set tblNew = objDoc.Tables.Add(Range:=rRange, NumRows:=LastProdHistRow, NumColumns:=10)




objDoc.Tables(2).Cell(3, 1).Range.Text = "Date"
objDoc.Tables(2).Cell(3, 2).Range.Text = "Volume"
objDoc.Tables(2).Cell(3, 3).Range.Text = "Begin Bates"
objDoc.Tables(2).Cell(3, 4).Range.Text = "End Bates"
objDoc.Tables(2).Cell(3, 5).Range.Text = "Documents"
objDoc.Tables(2).Cell(3, 6).Range.Text = "Redactions"
objDoc.Tables(2).Cell(3, 7).Range.Text = "Pages"
objDoc.Tables(2).Cell(3, 8).Range.Text = "Images"
objDoc.Tables(2).Cell(3, 9).Range.Text = "Natives"
objDoc.Tables(2).Cell(3, 10).Range.Text = "Slip-Sheets"
'objDoc.Tables(2).Cell(3, 11).Range.Text = "Size"
'objDoc.Tables(2).Cell(3, 12).Range.Text = "MB"
'objDoc.Tables(2).Cell(3, 13).Range.Text = "Bytes"
objDoc.Tables(2).Cell(LastProdHistRow + 6, 4).Range.Text = "Totals"
'************** End - Create Table with Production History



'Begin************** Copy Production History Array to  Word Table *************************

a = 4           ' The starting row of the table to begin copying data
For x = LBound(LastProdHist, 1) To UBound(LastProdHist, 1)
    b = 1
        For y = LBound(LastProdHist, 2) To UBound(LastProdHist, 2)
            Debug.Print x, y, LastProdHist(x, y)
            objDoc.Tables(2).Cell(a, b).Range.Text = LastProdHist(x, y)
            b = b + 1
        Next y
        a = a + 1
    Next x

'End**************  Produciton History Array to Word table ****************************
 
 
  With objDoc.Tables(2)
    .Rows(2).Cells.Merge
    .Cell(2, 1).Range.Text = "DOCUMENT PRODUCTION HISTORY"
    .Cell(2, 1).Range.Style = ("Heading 1")
    .Rows(3).Range.Font.Bold = True
    .Cell(LastProdHistRow, 4).Range.ParagraphFormat.Alignment = wdAlignParagraphRight
    **'Cell(LastProdHistRow, 5).Range.InsertFormula Formula:="=SUM(ABOVE)", NumberFormat:=""**
    .Rows(LastProdHistRow).Borders(wdBorderTop).LineStyle = wdLineStyleSingle
    .Rows(LastProdHistRow).Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
    '.Cell(LastProdHistRow, 5).Select
    'Selection.InsertFormula Formula:="=SUM(ABOVE)", NumberFormat:=""
    .Rows.SetLeftIndent LeftIndent:=0.5, RulerStyle:=wdAdjustNone
    '.Columns(10).SetWidth ColumnWidth:=64.65, RulerStyle:=wdAdjustNone
        
End With

我收到运行时错误 438 - 对象不支持此 属性 或在 table.

的 with 语句中使用的方法

Cell(LastProdHistRow, 5).Range.InsertFormula 公式:="=SUM(ABOVE)", NumberFormat:=""

我还尝试将其 select 作为 With 语句的最后一行并应用插入公式。但得到同样的错误。

'.Cell(LastProdHistRow, 5).Select 'Selection.InsertFormula Formula:="=SUM(ABOVE)", NumberFormat:=""

任何人都可以提供有关完成这项工作的后续步骤的线索吗?提前谢谢你。

Cell 上没有 InsertFormula 方法。

试试这个:

.Cell(LastProdHistRow, 5).Formula Formula:="=Sum(Above)"