【问题标题】:storing values in array and display in vba powerpoint将值存储在数组中并在 vba powerpoint 中显示
【发布时间】:2019-02-15 06:00:05
【问题描述】:

我正在尝试检查 PowerPoint 幻灯片中的红色字体。我想将包含红色字体的幻灯片编号存储在数组中并显示在单个对话框中。目前它在一个对话框中显示一个幻灯片编号。

我当前的代码如下所示。谁能告诉我如何将它存储为数组并显示它?

Private Sub CommandButton1_Click()

    Dim sld As Slide
    Dim shp As Shape
    Dim x As Byte

    With ActivePresentation
        z = .Slides(.Slides.Count).SlideNumber
        MsgBox z, vbDefaultButton1, "Total Slides"
    End With

    Dim myarray() As Integer
    ReDim myarray(0 To 2)

    For i = 2 To z
        Set sld = ActivePresentation.Slides(i)

        For Each shp In sld.Shapes
            If shp.TextFrame.TextRange.Font.Color.RGB = RGB(255, 0, 0) Then
                MsgBox i, vbDefaultButton2, "Slide with RED font"
            End If
        Next shp
    Next

End Sub

【问题讨论】:

    标签: arrays vba powerpoint


    【解决方案1】:

    我会使用 collection 这样的而不是数组

    Private Sub CommandButton1_Click()
    
    Dim sld As Slide
    Dim shp As Shape
    Dim x As Byte
    Dim z, i
    
        With ActivePresentation
            z = .Slides(.Slides.Count).SlideNumber
            MsgBox z, vbDefaultButton1, "Total Slides"
        End With
    
        Dim myCol As Collection
        Set myCol = New Collection
    
    
        For i = 2 To z
            Set sld = ActivePresentation.Slides(i)
            For Each shp In sld.Shapes
                If shp.TextFrame.TextRange.Font.Color.RGB = RGB(255, 0, 0) Then
                    ' MsgBox i, vbDefaultButton2, "Slide with RED font"
                    myCol.Add CStr(i), CStr(i)
                End If
            Next shp
        Next
    
        Dim j As Long
        For j = 1 To myCol.Count
            Debug.Print myCol.Item(j)
        Next j
    
    
    End Sub
    

    【讨论】:

    • 太完美了。有点不同,但做同样的事情。宾果游戏
    猜你喜欢
    • 1970-01-01
    • 2017-07-31
    • 1970-01-01
    • 2021-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多