任何人都可以帮我处理以下代码吗?我试图使用VBA删除PowerPoint演示文稿中的任何额外空格。
Sub removeSpaces()
Dim sld As Slide
Dim shp As Shape
For Each sld In ActivePresentation.Slides
For Each shp In sld.Shapes
Do While InStr(shp, " ") > 0
shp.Value = Replace(shp, " ", " ")
shp.Value = Trim(shp.Value)
Next shp
Next sld
End Sub
当我当前运行它时,它显示错误"未找到方法或数据成员"并突出显示" shp.Value"一部分。
答案 0 :(得分:0)
Shape
对象没有.Value
属性。 Instr
函数也可能无法针对Shape
对象进行评估。
https://msdn.microsoft.com/en-us/library/office/ff747227(v=office.14).aspx
通常,您需要参考形状TextFrame
,例如:
Dim shpText as String
For Each sld In ActivePresentation.Slides
For Each shp In sld.Shapes
If shp.HasTextFrame Then
shpText = shp.TextFrame.TextRange.Text 'Get the shape's text
Do While InStr(shpText, " ") > 0
shpText = Trim(Replace(shpText, " ", " "))
Loop
shp.TextFrame.TextRange.Text = shpText 'Put the new text in the shape
Else
shpText = vbNullString
End If
Next shp
Next sld
End Sub