PDA

View Full Version : Insert the pound sign if a cursor is active



Rosenrot
06-11-2019, 04:41 AM
Hi,

I am struggling to create a PowerPoint macro which inserts a pound sign:


If a cursor position is active – the pound sign appears
If it’s not a case, an error message appears reading: “Put your cursor somewhere”.


When I run the macro, error message appears regardless of cursor being active or not. Do you have any idea how to fix it?


Sub Insert_pound()


On Error GoTo ErrorHandler


With ActiveWindow.Selection.TextRange
.InsertAfter ("£")
End With


ErrorHandler:
MsgBox "Put your cursor somewhere"

End Sub

John Wilson
06-11-2019, 05:54 AM
The code will always get to the error message you need to add an exit


Sub Insert_pound()
On Error GoTo ErrorHandler
With ActiveWindow.Selection.TextRange
.InsertAfter ("£")
End With
Exit Sub
ErrorHandler:
MsgBox "Put your cursor somewhere"
End Sub