Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Dec 2009
    Location
    Rapid City, SD
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    macro to position cusor using "find"

    I have a word (2013) document and I want to move the five characters that follow gtg to the beginning of the line. I have recorded a macro by clicking "find" which gives the navigation input box and I type "gtg, enter" this highlights gtg and then I close the Navigation box by clicking the "X". I than do arrow right, "shift key+ arrow right 5 times. click copy. home, paste, space key, arrow down, home. The five characters are at the front of the first line and the cursor is now positioned at the front of the next line. This is what I want the macro to do but it does not record the clicks and key stroke for the "find" part. Following is the edit of the macro.

    Sub Macro3()
    '
    ' Macro3 Macro
    '
    '
    CommandBars("Navigation").Visible = False
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    Selection.MoveRight Unit:=wdCharacter, Count:=5, Extend:=wdExtend
    Selection.Copy
    Selection.HomeKey Unit:=wdLine
    Selection.PasteAndFormat (wdFormatOriginalFormatting)
    Selection.TypeText Text:=" "
    Selection.MoveDown Unit:=wdLine, Count:=1
    Selection.HomeKey Unit:=wdLine
    End Sub

    can some one give me VBA instructions that I can use to search for "gtg"? Also I would like to have this repeat to the end of the document.

    This is the first few lines of the document:

    a sower came from ancient hills (gtg 171).sbsong
    all with joyful exultation (gtg 798).sbsong
    amazing grace,how sweet the sound (gtg649).sbsong
    an upper room did our lord prepare (gtg 202).sbsong
    away in a manger (gtg 115) (ik).sbsong
    before the marvel of this night (gtg 125).sbsong

    Thanks

  2. #2
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts
    It seems to me you could do what you're after via a wildcard Find/Replace, where:
    Find = [!^13]@gtg ([0-9]@\))*^13
    Replace = \1. ^&
    No macros required (though you could record it as a macro). The above F/R will also work with numbers of any length following the gtg. The only line in your examples that might be a problem is the third, owing to a missing space between gtg and the number.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  3. #3
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Cross-posted at: http://answers.microsoft.com/en-us/o...c-7b6e81591b38

    Please read our policy on Cross-Posting in rule #14: http://windowssecrets.com/forums/faq...n#crossposting
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  4. #4
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts
    This is a simple way to achieve this:

    Code:
    Sub gtg()
        Dim x As Long
        
    again:
        Selection.Find.ClearFormatting
        With Selection.Find
            .Text = "gtg"
            .Forward = True
        End With
        Selection.Find.Execute
        Selection.Delete
        Selection.MoveLeft Unit:=wdCharacter, Count:=1
        Selection.MoveRight Unit:=wdCharacter, Count:=5, Extend:=wdExtend
        Selection.Cut
        Selection.HomeKey Unit:=wdLine
        Selection.Paste
        Selection.TypeText Text:=" "
        x = Selection.movedown(Unit:=wdLine, Count:=1)
        If x = 0 Then
            Exit Sub
        End If
        GoTo again:
    
    End Sub

  5. #5
    New Lounger
    Join Date
    Dec 2009
    Location
    Rapid City, SD
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Richard, I will give this a try.
    Ivan


    Quote Originally Posted by richardbarrett View Post
    This is a simple way to achieve this:

    Code:
    Sub gtg()
        Dim x As Long
        
    again:
        Selection.Find.ClearFormatting
        With Selection.Find
            .Text = "gtg"
            .Forward = True
        End With
        Selection.Find.Execute
        Selection.Delete
        Selection.MoveLeft Unit:=wdCharacter, Count:=1
        Selection.MoveRight Unit:=wdCharacter, Count:=5, Extend:=wdExtend
        Selection.Cut
        Selection.HomeKey Unit:=wdLine
        Selection.Paste
        Selection.TypeText Text:=" "
        x = Selection.movedown(Unit:=wdLine, Count:=1)
        If x = 0 Then
            Exit Sub
        End If
        GoTo again:
    
    End Sub

Posting Permissions

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