将样式应用于选定文本未选定框
Apply style to selected text not selected box
这对任何 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
捕获:
如果 Err.Number = -2147188160 那么 MsgBox CG_NOTHING_SELECTED
结束子
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
这对任何 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
捕获: 如果 Err.Number = -2147188160 那么 MsgBox CG_NOTHING_SELECTED 结束子
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