如何在表中引用图表对象

时间:2017-02-27 19:18:14

标签: vba ms-word word-vba

我在Word中有一个报告,文本和图像/图表组织成表格。

我正在尝试设置它,以便用户可以通过按下每个表顶部的ToggleButton控件来隐藏/显示这些表。我为按钮设置了以下VBA代码:

Sub ToggleCommand(btn As MSForms.ToggleButton, Optional TableNumber As Integer)

Application.ScreenUpdating = False

Dim objShape As InlineShape

Dim i As Integer

Dim NumberOfRows As Integer

NumberOfRows = ActiveDocument.Tables(TableNumber).Rows.Count

For i = 2 To NumberOfRows

  With ActiveDocument.Tables(TableNumber).Rows(i)

    If .HeightRule = wdRowHeightExactly Then
      .HeightRule = wdRowHeightAuto
      btn.Caption = "Hide"
      .Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
      .Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
      .Borders(wdBorderRight).LineStyle = wdLineStyleSingle

    Else
      btn.Caption = "Show"
      .HeightRule = wdRowHeightExactly
      .Height = ".5"
      .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
      .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
      .Borders(wdBorderRight).LineStyle = wdLineStyleNone

  End If

  End With

Next i

lbl_Exit:
  Exit Sub
End Sub

代码将显示/隐藏行而不会出现任何问题。但是如上所述,该表包含链接到Excel的图表。因此代码将折叠表的行并隐藏文本,但图表和图像仍然可见,并且不会与行一起折叠。

如何设置代码以便能够隐藏图表和行?

0 个答案:

没有答案