我看到this post但我无法修改用于PPT演示的VBA脚本。几乎每个幻灯片在文本框中都有文本。但是,在某些文本框的末尾有多个换行符(输入命中),在某些地方大约为1-3。我想要一个宏来删除那些不必要的换行符。告诉我我在做什么错在这里(2个脚本):删除Powerpoint VBA中的换行符
Sub RemoveSpaces(osh As Shape)
Dim oSl As Slide
Dim osh As Shape
With ActivePresentation
For Each oSl In .Slides
For Each osh In oSl.Shapes
With osh
If .HasTextFrame Then
If .TextFrame.HasText Then
If Right$(osh.TextFrame.TextRange.Characters(osh.TextFrame.TextRange.Length, 2)) = vbCrLf Then
osh.TextFrame.TextRange.Text = Left$(osh.TextFrame.TextRange.Text, Len(osh.TextFrame.TextRange.Text) - 2)
End If
End If
End If
End With
Next
Next
End With
End Sub
和
Sub RemoveSpaces()
Dim oSl As Slide
Dim osh As Shape
With ActivePresentation
For Each oSl In .Slides
For Each osh In oSl.Shapes
With osh
If .HasTextFrame Then
If .TextFrame.HasText Then
If osh.TextFrame.TextRange.Characters(osh.TextFrame.TextRange.Length - 2, 2).Text = vbCrLf Then
osh.TextFrame.TextRange.Characters(osh.TextFrame.TextRange.Length - 2, 2).Delete
End If
End If
End If
End With
Next
Next
End With
End Sub
出于某种原因,该脚本只能部分。在一些地方,它删除所有额外的空间,而在其他地方没有。当我将文本复制到即时窗口时,我看到那些空格用'男性符号'签名。也许某些条件,如“字母数字”或TRIM(characters.length -1,1).text =“”会工作吗? –