excel - 尽管操作成功,但对象需要错误
问题描述
我想构建由一组 12 个元素组成的许多不同的 PowerPoint 幻灯片(我称它们为“模板”)——对于每张幻灯片,只有元素的顺序和元素中的文本会发生变化。
目标:
遍历 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
解决方案
尝试使用wks.Cells(line, CLMN).Value
代替wks.Range(line, CLMN).Text
。
我认为line
andCLMN
是 Long 变量,代表Row
and Column
。
但是,如果line
aString
代表地址的文字部分(如“A”、“B”、“AB”),则必须使用wks.Range(line & CLMN).Value
推荐阅读
- powershell - 重定向到文件的 Netcat 数据包卡在缓冲区中
- mariadb - 无法在 mariadb 中增加 varchar 大小:使用的表类型不支持 BLOB/TEXT 列
- c# - 无法在 Microsoft 商店中为 Wpf Core Desktop Bridge 实施应用内购买
- javascript - Cypress cy.tick() 第二次调用时不转发时间
- kivy - cv2.Videocapture 几秒钟后关闭
- chainlink - 无法启动节点
- c - 得到前 50 个奇数的总和不是 5 的倍数?
- python - Python跳过多行字符串的第一行
- go - Golang 工作池 - 从作业中排队新作业
- flutter - 脚本 'C:\flutter\flutter\packages\flutter_tools\gradle\flutter.gradle' 行:1035