我想要构建许多不同的PowerPoint幻灯片,这些幻灯片由12组元素(我称之为“模板”)组成--对于每一张幻灯片,只有元素的顺序和元素中的文本发生了变化。
目标:
在Excel中遍历行。每一行表示“模具”的一种用法。在第5栏中,它说明使用什么“模具”(从ID),然后其他列包含字段的文本。
所有的模板都在演示文稿的最后一张幻灯片上,我从那里复制了相关的模板,粘贴起来,然后用文本填充。
其中一个模板是一个文本框,仅此而已(标题)。其他的都是形状的组。
当我试图运行这段代码时,它告诉我该行需要424个“对象”。
.TextFrame.TextRange.Text = wks.Range(line, CLMN).Text成功运行后的...but。标题在幻灯片上,文本是正确的。
它怎么能在事实发生之后要求一个对象?
全分庭:
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

发布于 2020-03-21 21:11:22
尝试使用wks.Cells(line, CLMN).Value而不是wks.Range(line, CLMN).Text。
我认为line和CLMN是长变量,表示Row和Column。
但是,如果line是一个String,表示地址的字面部分(如"A“、"B”、"AB"),则必须使用wks.Range(line & CLMN).Value
https://stackoverflow.com/questions/60793128
复制相似问题