我想构建许多不同的PowerPoint幻灯片,这些幻灯片由一组12个元素组成(我称它们为“模具”)-对于每个幻灯片,仅元素的顺序和元素中的文本都会更改。
目标:
在Excel中浏览各行。每一行代表一种“模板”的用法。在第5列中,它说明要使用的“模板”(来自ID),然后其他列包含字段的文本。
所有模具都在演示文稿的最后一张幻灯片上,在该幻灯片上,我复制了相关模板,将其粘贴并填充文本。
其中一个模板是文本框(标题)。其他所有的都是形状组。
当我尝试运行此代码时,它告诉我该行的424“对象必需”
.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
答案 0 :(得分:2)
尝试使用wks.Cells(line, CLMN).Value
代替wks.Range(line, CLMN).Text
。
我假设line
和CLMN
是Long变量,代表Row
和Column
。
但是,如果line
是表示地址文字部分(例如“ A”,“ B”,“ AB”)的String
,则必须使用wks.Range(line & CLMN).Value