【问题标题】:Apply style to selected text not selected box将样式应用于选定文本未选定框
【发布时间】:2019-01-21 14:52:00
【问题描述】:

这对于任何 VBA 专家来说都很容易,所以对于新手问题表示歉意!我有一个将文本压缩到文本框中的代码。目前,代码压缩了文本框中的所有文本,但我希望代码仅适用于选定的文本。如何修改此代码以使其正常工作?

非常感谢提前! PJ

Sub CondenseText()

On Error GoTo Catch


Dim o As Shape, b As Boolean
Set o = ActiveWindow.Selection.ShapeRange(1)
If Not o Is Nothing Then
    With o
        .TextFrame2.TextRange.Font.Spacing = .TextFrame2.TextRange.Font.Spacing - 0.1
    End With
End If
Exit Sub

捕捉: If Err.Number = -2147188160 Then MsgBox CG_NOTHING_SELECTED 结束子

【问题讨论】:

    标签: vba powerpoint


    【解决方案1】:
    Sub CondenseText()
    
    Dim oTextRange2 As TextRange2
    
    ' You can check Selection.Type rather than relying
    ' on an errorhandler if you like
    If ActiveWindow.Selection.Type = ppSelectionText Then
    
        Set oTextRange2 = ActiveWindow.Selection.TextRange2
    
        If Not oTextRange2 Is Nothing Then
            oTextRange2.Font.Spacing = oTextRange2.Font.Spacing - 0.1
        End If
    
    ' and you could add an Else clause with msg for the 
    ' user here if you like:
    Else
        MsgBox "Yo! Select some text first, OK?"    
    End If
    
    End Sub
    

    【讨论】:

    • 除了天才我还能说什么?!!非常感谢!
    猜你喜欢
    • 2013-05-25
    • 2014-04-18
    • 1970-01-01
    • 2019-07-25
    • 2010-09-11
    • 2022-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多