2017-04-06 63 views
1

我是VBA宏的新手,試圖編寫一個宏來隱藏Powerpoint表中的空白行。我不確定要使用哪些屬性以及如何繼續前進。如何使用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 
+0

不要以爲有可能在PowerPoint中隱藏行... – Jbjstam

回答

0

我認爲您需要刪除該行。沒有辦法在PowerPoint中隱藏它。如果您需要保留原始表格,可能需要複製它,將原始的.Visible屬性設置爲False,然後修改副本。

這是一個關於它的方法。總體思路:對於每一行,將行中每個單元格的文本累加到一個臨時字符串中。如果字符串的長度爲0,那麼它是一個空行...刪除它。

爲了使其起作用,您必須向後退一步行,否則內部For/Next計數器在刪除行時不同步。

Option Explicit '總是以此開始;節省一個麻煩的世界,讓你誠實

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