Share via

certain keystrokes for Macro won't record

Anonymous
2011-12-02T20:46:12+00:00

I’m trying to create a certain keyboard macro (using the Record Macro function on the button on the ribbon in Word 2010), a macro that transposes the two typed characters to the right of the cursor.  (I make a lot of typing errors like that.)  Thus, if I mistakenly type the list of numbers 12435, and then place the cursor before the “4”, the macro would transpose the “4” and the “3” so that my list would then be in the correct order.

Using keyboard strokes, I would do this manually as follows:

  1. Press Shift and hold it down, tap the right arrow key, release both.  (This selects the “4”.)
  2. Tap the F2 key.  (This activates “Move to Where?”)
  3. Tap the right arrow key twice.  (This tells it I want to move the selection (the “4”) two characters to the right, which would place it after the “3”.)
  4. Tap “Enter”.  (This completes the “move”.)
  5. Tap the left arrow key twice.  (This tells it I want to move the cursor two characters to the left, which would put it back where it started, which is where I want to be to continue typing.)

When I try to record this keystroke sequence, something is not taking.  I am able to record a simple macro, for example, typing a single letter.  That works.  But I can’t record this one.  Somewhere in the F2 area it seems to stop working.

What’s up?  Are there certain keystrokes that the “Record Macro” function won’t take?  FYI, it shows the following when I "view" the macro after I record it and it doesn't work.  In this case, I named it "b" and gave it the Alt-B keyboard shortcut.

b b()

'

' b Macro

'

'

    Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend

    Selection.MoveRight Unit:=wdCharacter, Count:=2

    Selection.MoveLeft Unit:=wdCharacter, Count:=2

End Sub

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Jay Freedman 207.7K Reputation points Volunteer Moderator
2011-12-02T21:48:32+00:00

No, this action cannot be recorded -- there are many keystrokes that can't be recorded, and many useful things that macros can do that can't be done with keystrokes at all. And to top it off, there are situations where the recorder simply gets it wrong (http://www.word.mvps.org/FAQs/MacrosVBA/ModifyRecordedMacro.htm).

To learn how to enter macros (the ones Hans and Doug showed you involve only copying and pasting, not typing), read http://www.gmayor.com/installing_macro.htm.

Was this answer helpful?

0 comments No comments

6 additional answers

Sort by: Most helpful
  1. Anonymous
    2011-12-02T21:34:34+00:00

    Again, I must restate that I do not know how to do this the way  you want.  **Can this macro be recorded keystroke by keystroke using the little "tape recorder" Record Macro function on the ribbon?  Yes or No?**If not, I guess I will need to learn (I asume it's pretty simple) how to do it by typing these lines of code, to create it and name it and assign a hotkey.)

    Also I don't care about the Clipboard, whatever's on there can go away, i never keep anything on it.

    Was this answer helpful?

    0 comments No comments
  2. Doug Robbins - MVP - Office Apps and Services 323.1K Reputation points MVP Volunteer Moderator
    2011-12-02T21:28:18+00:00

    Here's another way (that will not interfere with anything that you might have on the clipboard)

    Dim rng As Range

    Set rng = Selection.Range

    With rng

        .End = .End + 2

        .Text = Mid(.Text, 2) & Left(.Text, 1)

    End With

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2011-12-02T21:22:59+00:00

    Actually this did not help.  I don't know how to create macros using the code etc.  I tried it now and couldn't figure out how to name it, assign a key, etc.  My question stated that I wanted to record it using the Record macro function on the button on the ribbon, simply typing in the needed keystrokes.  Is it possible to do that?

    Was this answer helpful?

    0 comments No comments
  4. HansV 462.6K Reputation points
    2011-12-02T21:00:25+00:00

    Try this version:

    Sub b()

    '

    ' b Macro

    '

    '

        Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend

        Selection.Cut

        Selection.MoveRight Unit:=wdCharacter, Count:=1

        Selection.Paste

        Selection.MoveLeft Unit:=wdCharacter, Count:=2

    End Sub

    Was this answer helpful?

    0 comments No comments