VBA:基于Excel表更新形状属性

时间:2020-10-02 21:58:19

标签: excel vba powerpoint

我有一个Excel表,其中包含从PowerPoint文件中提取的A:L列中的所有属性。我正在尝试根据表格中列出的属性更新PowerPoint中的形状(即填充颜色显示为红色,然后在Excel中将其更改为蓝色,然后单击执行并在PowerPoint中进行更新)。知道为什么这失败了吗?

我有以下代码,但在以下行中失败:

    For Each oSl In oSlides

Error: Runtime Error '424' Object required
Sub test()
    Dim PPT As PowerPoint.Application
    Dim pres As PowerPoint.Presentation
    Dim newslide As PowerPoint.Slide
    Dim slideCtr As Integer
    Dim tb As PowerPoint.Shape
    Dim i As Long: i = 1
    Dim oShAttributes As Range
    Dim oSlides As Slides
    Dim oSl As Slide
    Dim oSh As Shape
    
    Set oShAttributes = Range("A1:L5")

    Set PPT = CreateObject("PowerPoint.Application")
    PPT.Visible = True
    Set oSlides = PPT.Presentations.Open( _
        "C:\Users\xxxx\Documents\vbatest.pptx")
    slideCtr = 1

    For Each oSl In oSlides
        For Each oSh In oSl.Shapes
            oSh.Name = oShAttributes(i, 2)
            oSh.Fill.ForeColor.RGB = oShAttributes(i, 3)
            oSh.TextFrame.TextRange.Font.Name = oShAttributes(i, 4)
            oSh.TextFrame.TextRange.Font.Size = oShAttributes(i, 5)
            oSh.TextFrame.TextRange.Font.Color.RGB = oShAttributes(i, 6)
            oSh.TextFrame.TextRange.Text = oShAttributes(i, 7)
            oSh.Left = oShAttributes(i, 9)
            oSh.Top = oShAttributes(i, 10)
            oSh.Width = oShAttributes(i, 11)
            oSh.Height = oShAttributes(i, 12)
            i = i + 1
        Next oSh
    Next oSl
    
End Sub

0 个答案:

没有答案