Consulting

Results 1 to 2 of 2

Thread: Insert the pound sign if a cursor is active

  1. #1

    Insert the pound sign if a cursor is active

    Hi,

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

    1. If a cursor position is active – the pound sign appears
    2. 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

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    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
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •