尽管操作成功,VBA对象仍需要错误

问题描述 投票:0回答:1

我想为powerpoint写一个宏,它可以构建许多不同的幻灯片,这些幻灯片由一组12个元素组成(我称它们为”模具”)-对于每个幻灯片,只有元素的顺序和元素中的文字会发生变化。

目标:在excel中浏览行。每一行代表一种“模板”的用法。在第5列中,它说明了要使用的“模板”(来自ID),然后其他列包含了字段的文本。所有模具都在演示文稿的最后一张幻灯片上,在该幻灯片中,我复制了相关模板,然后粘贴并填充文本。

不幸的是,其中一个模板只是一个文本框(标题)。其他所有的都是形状组。

[当我尝试运行此代码时,它告诉我该行的424“ Object required”

 .TextFrame.TextRange.Text = wks.Range(line, CLMN).Text

...但是成功运行后:标题在幻灯片上并且文本正确。

有人可以帮我吗?到底是怎么回事?事实发生后如何要求对象?

完整子:

Sub AddShape(typ As Integer, state As Integer, currentSld As Slide, height As Long, line As Integer)

    'Set the constants (although not implemented as Const)
    Dim CLMN As Integer
    CLMN = 5
    Dim stencils As Shapes
    Dim stencilSlide As Integer
    stencilSlide = CInt(ActivePresentation.Slides.Count)
    Set stencils = ActivePresentation.Slides(stencilSlide).Shapes

    Dim HEADER As Shape
    Set HEADER = stencils("header")

    Dim ALPHANUMERICAL As Shape
    Set ALPHANUMERICAL = stencils("alphanumerical")

    Dim BIRTHDATE As Shape
    Set BIRTHDATE = stencils("birthdate")

    Dim TOGGLE As Shape
    Set TOGGLE = stencils("toggle")

    Dim DROPDOWN As Shape
    Set DROPDOWN = stencils("dropdown")

    Dim NUMERICAL As Shape
    Set NUMERICAL = stencils("numerical")

    Select Case typ
    Case 1
        ALPHANUMERICAL.Copy
    Case 2
        NUMERICAL.Copy
    Case 4
        DROPDOWN.Copy
    Case 5
        TOGGLE.Copy
    Case 9
        BIRTHDATE.Copy
    End Select

    If typ = 10 Then
        HEADER.Copy
        With currentSld.Shapes.Paste
            .Top = height
            .TextFrame.TextRange.Text = wks.Range(line, CLMN).Text
        End With
    Else
        With currentSld.Shapes.Paste
                .Top = height
                    For x = 1 To .GroupItems.Count
                        If .GroupItems(x).Name = "label" Then
                            With .GroupItems(x)
                                .TextFrame.TextRange.Text = wks.Range(line, CLMN).Text
                            End With
                        Else
                            With .GroupItems(x)
                                .TextFrame.TextRange.Text = wks.Range(line, CLMN + CInt(.GroupItems(x).Name)).Text
                            End With
                        End If

                    Next
        End With
    End If


End Sub

enter image description here

vba excel-vba powerpoint powerpoint-vba
1个回答
0
投票

尝试使用wks.Cells(line, CLMN).Text代替wks.Range(line, CLMN).Text

© www.soinside.com 2019 - 2024. All rights reserved.