Share via

record macro with inserted text

Anonymous
2012-09-26T02:35:45+00:00

I'm sure there is a very simple solution to this, but I'm not seeing it and haven't been able to find it in the HELP pages.  I want to record a MACRO that will allow me to type some info, press a button and have the info, along with additional info already in the MACRO to magically appear where and how I want it.  My current need is to write directions for a craft pattern.  I want to type the number of stitches in a particular color without constantly having to retype the name of the colors or the type of stitch.  For example:

BLACK - 14k, PINK - 18p

I would want a MACRO to have BLACK - (whatever I need here to be able to just type the number and press the MACRO shortcut) k,

I would want another MACRO to have PINK - (whatever I need here to be able to just type the number and press the MACRO shortcut) p

To use, I'd type 14 then press the Macro key, then type 18 and press another Macro key.

Thanks!!!

KJ

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

Doug Robbins - MVP - Office Apps and Services 323.1K Reputation points MVP Volunteer Moderator
2012-09-26T04:10:04+00:00

I'm sure there is a very simple solution to this, but I'm not seeing it and haven't been able to find it in the HELP pages.  I want to record a MACRO that will allow me to type some info, press a button and have the info, along with additional info already in the MACRO to magically appear where and how I want it.  My current need is to write directions for a craft pattern.  I want to type the number of stitches in a particular color without constantly having to retype the name of the colors or the type of stitch.  For example:

BLACK - 14k, PINK - 18p

I would want a MACRO to have BLACK - (whatever I need here to be able to just type the number and press the MACRO shortcut) k,

I would want another MACRO to have PINK - (whatever I need here to be able to just type the number and press the MACRO shortcut) p

To use, I'd type 14 then press the Macro key, then type 18 and press another Macro key.

Thanks!!!

KJ

Use the following code:

Selection.Text = "BLACK " & InputBox("Enter the number of black stitches") & "p"

That will display an input box into which you would insert the number (14) and then when you press Enter, it will insert

BLACK 14p

at the location of the cursor.

Was this answer helpful?

0 comments No comments

Answer accepted by question author

Anonymous
2012-09-26T04:08:33+00:00

The following should work for you

Sub Black()

Dim oRng As Range

Set oRng = Selection.Range

oRng.MoveStart wdWord, -1

oRng.InsertBefore "Black - "

oRng.Collapse wdCollapseEnd

oRng.Select

End Sub

Sub Pink()

Dim oRng As Range

Set oRng = Selection.Range

oRng.MoveStart wdWord, -1

oRng.InsertBefore "Pink - "

oRng.Collapse wdCollapseEnd

oRng.Select

End Sub

Assign the macros to buttons on the QAT (Quick Access Toolbar) of to keyboard shortcuts - see http://www.gmayor.com/installing_macro.htm

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2012-09-26T06:52:45+00:00

    My many thanks to both of you!

    KJ

    Was this answer helpful?

    0 comments No comments