我看到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 =「」會工作嗎? –