Reputation:
this is going to be easy for any VBA expert out there so, apologies for the novice question! I have a code to condense text into a text box. At the moment the code condensed all the text inside the text box but I want the code to work for selected text only. How can I modify this code to make it work?
Many thanks on advance! 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
Catch: If Err.Number = -2147188160 Then MsgBox CG_NOTHING_SELECTED End Sub
Upvotes: 0
Views: 54
Reputation: 14809
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
Upvotes: 0