我在 Word 程序中有一个如下的表格:
通过打开此表格文件,我必须增加或减少行数。因此,我无法使用季节总和公式(因为单元格数量会发生变化)。您认为,我该如何总结“第一季总计“ 和 ”第 2 季“并将其放入”总季数“?你认为我能否得到“全季”这个词的帮助,或者选择大胆的单词虚拟专用网络?
答案1
答案2
各位试图帮助我的朋友们,大家好!我当天就研究了这个主题,并通过编写以下代码成功解决了这个问题。我将这段代码放在这里供大家参考。如果朋友们愿意,他们可以提供更好的代码,以便更轻松、更快地运行。要开心...
Sub CalculatingTotalSeasons()
ActiveDocument.Tables(1).Select
Selection.Copy
Selection.EndKey Unit:=wdStory
Selection.TypeParagraph
Selection.PasteAndFormat (wdFormatOriginalFormatting)
Dim t As Table
Dim r As Row
Dim ts As String
Set t = ActiveDocument.Tables(2)
ts = "Total Season"
For Each r In t.Rows
If Left(r.Cells(1).Range.Text, 12) <> ts Then r.Delete
Next r
With ActiveDocument.Tables(2)
ActiveDocument.Tables(2).Cell(1, 1).Select
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Total Seasons"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCell
Selection.InsertFormula Formula:="=SUM(ABOVE)", NumberFormat:=""
Selection.MoveLeft Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.Copy
ActiveDocument.Tables(2).Delete
End With
ActiveDocument.Tables(1).Select
With ActiveDocument.Tables(1)
ActiveDocument.Tables(1).Cell(1, 1).Select
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Total Seasons"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCell
Selection.PasteAndFormat (wdFormatPlainText)
End With
End Sub