在Powerpoint表中以及使用vba的幻灯片中发现空单元格时发出警报

时间:2019-07-10 16:20:53

标签: powerpoint-vba

我必须查找并警告在Power Point的每个表中是否都找到空单元格。

我找到了下面的代码here,但是它不起作用,因此不应为所有表而不是选定的表都找到它。

    Sub CheckTableCells()

    Dim oCell As Cell
    Dim oRow As Row
    Dim MyRange As Range

    For Each oRow In Selection.Tables(1).Rows
        For Each oCell In oRow.Cells
            If Selection.Text = Chr(13) & Chr(7) Then
                oCell.Select
                MsgBox oCell.RowIndex & " " & oCell.ColumnIndex & " is empty."
            End If
        Next oCell
    Next oRow

    End Sub

请任何人帮助我。

enter image description here

1 个答案:

答案 0 :(得分:2)

此代码循环遍历活动演示文稿中的每张幻灯片,并在每张幻灯片中,检查幻灯片上的每个形状是否包含表格,如果包含,则检查每个单元格是否为空白。干杯。

Sub CheckTableCells()

    Dim vSlide As Slide
    Dim vShape As Shape
    Dim vRow As Long
    Dim vColumn As Long

    For Each vSlide In Application.ActivePresentation.Slides
        For Each vShape In vSlide.Shapes
            If vShape.HasTable Then
                For vRow = 1 To vShape.Table.Rows.Count
                    For vColumn = 1 To vShape.Table.Columns.Count
                        If vShape.Table.Cell(vRow, vColumn).Shape.TextFrame.TextRange.Text = "" Then
                            MsgBox vSlide.Name & " Table: """ & vShape.Name & """ cell (" & vRow & "," & vColumn & ") is blank."
                        End If
                    Next
                Next
            End If
        Next
    Next

End Sub

screen