2015-08-08 185 views
0

我看到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 

回答

0

当我按在PowerPoint中输入,它显然增加了一个垂直选项卡是11.尝试的ASCII码如下:

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 
        Do While osh.TextFrame.TextRange.Characters(osh.TextFrame.TextRange.Length - 1, 1).Text = Chr(11) 
         osh.TextFrame.TextRange.Characters(osh.TextFrame.TextRange.Length - 1, 1).Delete 
        Loop 
       End If 
      End If 
     End With 
    Next 
Next 

    End With 
End Sub 
+0

出于某种原因,该脚本只能部分。在一些地方,它删除所有额外的空间,而在其他地方没有。当我将文本复制到即时窗口时,我看到那些空格用'男性符号'签名。也许某些条件,如“字母数字”或TRIM(characters.length -1,1).text =“”会工作吗? –

1

Powerpoint的这种方式有点怪异;行和段落结尾可能会有所不同,具体取决于您拥有的PPT版本以及形状是标题占位符还是其他类型的形状。

我得在PowerPoint中常见问题我认为,更详细地解释一个页面:

段落结束和换行符 http://www.pptfaq.com/FAQ00992_Paragraph_endings_and_line_breaks.htm

+0

我正在使用PowerPoint 2013.不确定此信息仍然有效。当粘贴到即时窗口时,我看到'男性标志'。就像这里:http://stackoverflow.com/questions/4091345/what-is-this-strange-character-and-how-can-i-get-rid-of-it –

+0

该信息仍然有效。男性的标志是Chr $(11)。我更新了常见问题解答页面,以反映这些信息适用于PPT 2007 *及以后*。感谢您的推动。 –