PDA

View Full Version : Apply style to selected text not selected box



Exposian
01-21-2019, 03:41 AM
Hi guys!
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

John Wilson
01-29-2019, 10:04 AM
Sub CondenseText()
On Error GoTo Catch
Dim o As TextRange2, b As Boolean
Set o = ActiveWindow.Selection.TextRange2
If Not o Is Nothing Then
With o
.Font.Spacing = .Font.Spacing - 0.1
End With
End If
Exit Sub
Catch:
If Err.Number = -2147188160 Then MsgBox "NOTHING_SELECTED"
End Sub