Results 1 to 4 of 4
  1. #1
    Lounger
    Join Date
    Dec 2009
    Location
    White Bear Lake, MN
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts
    As a programmer, I am an avid keyboard shortcuts user in every Windows app. On Win7 in Word 2007, while documenting a database app, I have many underscores in the text that I'm trying to select (then change font or color, etc). While Ctrl+{left arrow} the cursor stops at all underscores. This speedy navigation feature happens in Notepad but not in Word. Is there a way to tell Word that I don't want Ctrl+{left arrow} to stop at underscores? or perhaps a setting that makes Ctrl+{left arrow} stop only at spaces? This would GREATLY speed up my documentation tasks!

    btw: it works correctly in this message editor (in Google Chrome). When I Ctrl+{left arrow} through stg_this_label_is_full_of_them, Ctrl+{left arrow} skips to the next space. Win7 Wordpad is also wrong.

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    Quote Originally Posted by Guitarzan8 View Post
    On Win7 in Word 2007, while documenting a database app, I have many underscores in the text that I'm trying to select (then change font or color, etc). While Ctrl+{left arrow} the cursor stops at all underscores. This speedy navigation feature happens in Notepad but not in Word.
    Notepad views spaces as the only valid "word" boundaries while Word recognizes many (most?) forms of punctuation as a word boundary for purposes of its Word selection functions. I think you could write a macro to work around this, i.e., hijack the WordLeft function associated with the Ctrl+LeftArrow shortcut. Here's a rough draft of such a function:

    Code:
    Sub WordLeftToSpace()
    'Hijack! Move insertion point to space before the word to the left
    With Selection
        If .Previous.Text = " " Then
            .MoveLeft wdCharacter, 1, wdExtend
        End If
        .MoveStartUntil " ", wdBackward
        If Selection.Characters.Count <= 1 Then
            ' May be at a boundary with no space
            .MoveStart wdLine, -1
        End If
        .Collapse wdCollapseStart
    End With
    End Sub
    You can assign this to the key combination of your choice in Word Options > Customize > Keyboard Shortcuts: Customize

  3. #3
    Lounger
    Join Date
    Dec 2009
    Location
    White Bear Lake, MN
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks jscher! That was exactly what I after!

    Im trying to make the Ctrl+right do the opposite and its acting retarded. What's wrong with this?


    Code:
    Sub WordRightToSpace()
    'Hijack! Move insertion point to space after the word to the right
    With Selection
        If .Next.Text = " " Then
            .MoveRight wdCharacter, 1, wdExtend
        End If
        .MoveStartUntil " ", wdForward
        If Selection.Characters.Count <= 1 Then
            ' May be at a boundary with no space
            .MoveEnd wdLine, 1
        End If
        .Collapse wdCollapseStart
    End With
    End Sub

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    Quote Originally Posted by Guitarzan8 View Post
    Im trying to make the Ctrl+right do the opposite and its acting retarded. What's wrong with this?
    There are a number of changes you have to make. First, Selection.Previous and Selection.Next work differently because the Selection.Text at an insertion point reads the next character. Second, because the end of document, end of paragraph, or end of table cell is swept up in the end of line, you have to back off from that. And of course change the other Starts to Ends... Here's a rough draft:

    Code:
    Sub WordRightToSpace()
    'Hijack! Move insertion point to space after the word to the right
    With Selection
        While .Text = " "  ' Skip past spaces up to the next non-space character
            .MoveRight wdCharacter, 1, wdMove
        Wend
        .MoveEndUntil " ", wdForward ' Select to the next space (if any)
        If Selection.Characters.Count <= 1 Then
            ' May be at a boundary with no space
            .MoveEnd wdLine, 1
            .MoveEnd wdCharacter, -1
        Else
            .MoveEnd wdCharacter, 1
        End If
        .Collapse wdCollapseEnd
    End With
    End Sub
    Hope that helps.

Posting Permissions

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