我目前正在读取一个excel表,并在MS-word中生成一个表单,其中包含来自excel表的匹配记录。我是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当在表的with语句中使用该属性或方法时,我得到运行时错误438 - object不支持该属性或方法。
单元(LastProdHistRow,5).Range.InsertFormula Formula:=“=SUM(上图)”,NumberFormat:=“”
我还尝试选择它作为With语句中的最后一行,并应用插入公式。但也有同样的错误。
'.Cell(LastProdHistRow,5).Select 'Selection.InsertFormula Formula:=“=SUM(上)”,NumberFormat:=“”
有人能提供一个线索来说明下一步的工作吗?提前谢谢你。
发布于 2020-10-05 23:36:24
在一个InsertFormula上没有Cell方法。
试试这个:
.Cell(LastProdHistRow, 5).Formula Formula:="=Sum(Above)"https://stackoverflow.com/questions/64217380
复制相似问题