如何使用vba隐藏Powerpoint表中的空白行?

时间:2017-04-06 02:35:36

标签: vba powerpoint powerpoint-vba

我是VBA宏的新手,并尝试编写一个宏来隐藏Powerpoint表中的空白行。我不确定要使用哪些属性以及如何继续使用。

Sub TableRowHide()

Dim sl as Slide
Dim shTable as Shape
Dim pres as Presentation
Dim irow as Integer
Dim icol as Integer
Dim counter as Integer

Set pres = ActivePresentation

With sh.Table

  For irow = 1 to .Rows.Count
     counter = 0
   For icol = 1 to .Columns.Count

   If shTable.table.Cell(irow,icol).Shape.Textframe.Textrange.Text = "" 
     Then --------------

     counter = counter + 1
     End If

     If counter = .Columns.Count Then --------

      Else   ------------

   Next icol

   Next irow

  End With

   End Sub

1 个答案:

答案 0 :(得分:0)

我认为您需要删除该行。没有办法将其隐藏在PowerPoint中。如果您需要保留原始表,或者复制它,将原始的.Visible属性设置为False,然后修改副本。

这是一种解决问题的方法。一般思路:对于每一行,将行中每个单元格的文本累积为临时字符串。如果字符串的长度为0,那么它是一个空白行...删除它。

为了使其正常工作,您必须在行中向后退,否则当您删除行时,内部For / Next计数器会不同步。

选项明确 '总是从这开始;拯救世界的麻烦,让你诚实

Sub DeleteBlankRows()

    Dim oTbl As Table
    Dim lRow As Long
    Dim lCol As Long
    Dim sTemp As String

    Set oTbl = ActiveWindow.Selection.ShapeRange(1).Table

    With oTbl

        For lRow = .Rows.Count To 1 Step -1
            sTemp = ""
            For lCol = 1 To .Columns.Count
                sTemp = sTemp & .Cell(lRow, lCol).Shape.TextFrame2.TextRange.Text
            Next
            If Len(sTemp) = 0 Then
                .Rows(lRow).Delete
            End If
        Next    ' row

    End With    ' oTbl

End Sub