How can I set a repeated action to a shortcut key?

K

Ken A. Dienne

OK, so I've searched everywhere, and read up on the websites for WORD 2007,
but I can't figure out how to set a repeated action to a shortcut key. I've
tried recording a macro, but it hasn't worked so far ... maybe I'm just not
doing it properly. Anyway, here's what I'd like to do:

I write long exercises for ESL textbooks, which include superscripted
notations (i.e. numbers inside brackets) in front of the answer blanks, and
I'd like to figure out a way for WORD to 'superscript all brackets and their
contents' at the press of a key or click of a button. Right now, I have to
highlight each bracket-number set individually, holding down 'control', and
then hit the 'superscript' button. It's the highlighting of multiple items
that drives me crazy ...

If anyone knows how I can set this up, I'd be very grateful for the tip.

Cheers!

K
 
J

Jay Freedman

OK, so I've searched everywhere, and read up on the websites for WORD 2007,
but I can't figure out how to set a repeated action to a shortcut key. I've
tried recording a macro, but it hasn't worked so far ... maybe I'm just not
doing it properly. Anyway, here's what I'd like to do:

I write long exercises for ESL textbooks, which include superscripted
notations (i.e. numbers inside brackets) in front of the answer blanks, and
I'd like to figure out a way for WORD to 'superscript all brackets and their
contents' at the press of a key or click of a button. Right now, I have to
highlight each bracket-number set individually, holding down 'control', and
then hit the 'superscript' button. It's the highlighting of multiple items
that drives me crazy ...

If anyone knows how I can set this up, I'd be very grateful for the tip.

Cheers!

K

Step 1: Recognize that the easiest way to do this is a wildcard search & replace
(http://www.gmayor.com/replace_using_wildcards.htm) in which the only difference
between the found text and the replacement text is the superscript formatting.
One click of the Replace All button will reformat every notation in the whole
document -- and doing it again and again won't change the ones that are already
superscript.

In this case, the Find What expression should be

\[*\]

Because the brackets have special meaning in a wildcard search, the backslashes
are needed to tell Word to search for actual brackets in the text. The asterisk
represents any characters that occur between left and right brackets.

The Replace With expression should be

^&

which is the code for "the same characters that were matched". While the cursor
is in the Replace With box. press Ctrl+Shift+= to apply Superscript formatting
(or go through the Format > Font button in the bottom left of the Replace dialog
and check the Superscript box).

Then click the Replace All button.

This can be recorded as a macro, which can be assigned to a button on the Quick
Access Toolbar or to a keyboard shortcut.
 
K

Ken A. Dienne

Thanks - that's brilliant! :)

K

Jay Freedman said:
OK, so I've searched everywhere, and read up on the websites for WORD 2007,
but I can't figure out how to set a repeated action to a shortcut key. I've
tried recording a macro, but it hasn't worked so far ... maybe I'm just not
doing it properly. Anyway, here's what I'd like to do:

I write long exercises for ESL textbooks, which include superscripted
notations (i.e. numbers inside brackets) in front of the answer blanks, and
I'd like to figure out a way for WORD to 'superscript all brackets and their
contents' at the press of a key or click of a button. Right now, I have to
highlight each bracket-number set individually, holding down 'control', and
then hit the 'superscript' button. It's the highlighting of multiple items
that drives me crazy ...

If anyone knows how I can set this up, I'd be very grateful for the tip.

Cheers!

K

Step 1: Recognize that the easiest way to do this is a wildcard search & replace
(http://www.gmayor.com/replace_using_wildcards.htm) in which the only difference
between the found text and the replacement text is the superscript formatting.
One click of the Replace All button will reformat every notation in the whole
document -- and doing it again and again won't change the ones that are already
superscript.

In this case, the Find What expression should be

\[*\]

Because the brackets have special meaning in a wildcard search, the backslashes
are needed to tell Word to search for actual brackets in the text. The asterisk
represents any characters that occur between left and right brackets.

The Replace With expression should be

^&

which is the code for "the same characters that were matched". While the cursor
is in the Replace With box. press Ctrl+Shift+= to apply Superscript formatting
(or go through the Format > Font button in the bottom left of the Replace dialog
and check the Superscript box).

Then click the Replace All button.

This can be recorded as a macro, which can be assigned to a button on the Quick
Access Toolbar or to a keyboard shortcut.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.
 
K

Ken A. Dienne

Actually, while I have you, would you mind giving me the wildcard
instructions for finding the first word after the superscripted notations I
referred to above. I'd like to record another macro to find the first word
after the notations (so that I can make some font changes, etc).

Thanks in advance!

Ken

Ken A. Dienne said:
Thanks - that's brilliant! :)

K

Jay Freedman said:
OK, so I've searched everywhere, and read up on the websites for WORD 2007,
but I can't figure out how to set a repeated action to a shortcut key. I've
tried recording a macro, but it hasn't worked so far ... maybe I'm just not
doing it properly. Anyway, here's what I'd like to do:

I write long exercises for ESL textbooks, which include superscripted
notations (i.e. numbers inside brackets) in front of the answer blanks, and
I'd like to figure out a way for WORD to 'superscript all brackets and their
contents' at the press of a key or click of a button. Right now, I have to
highlight each bracket-number set individually, holding down 'control', and
then hit the 'superscript' button. It's the highlighting of multiple items
that drives me crazy ...

If anyone knows how I can set this up, I'd be very grateful for the tip.

Cheers!

K

Step 1: Recognize that the easiest way to do this is a wildcard search & replace
(http://www.gmayor.com/replace_using_wildcards.htm) in which the only difference
between the found text and the replacement text is the superscript formatting.
One click of the Replace All button will reformat every notation in the whole
document -- and doing it again and again won't change the ones that are already
superscript.

In this case, the Find What expression should be

\[*\]

Because the brackets have special meaning in a wildcard search, the backslashes
are needed to tell Word to search for actual brackets in the text. The asterisk
represents any characters that occur between left and right brackets.

The Replace With expression should be

^&

which is the code for "the same characters that were matched". While the cursor
is in the Replace With box. press Ctrl+Shift+= to apply Superscript formatting
(or go through the Format > Font button in the bottom left of the Replace dialog
and check the Superscript box).

Then click the Replace All button.

This can be recorded as a macro, which can be assigned to a button on the Quick
Access Toolbar or to a keyboard shortcut.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.
 
J

Jay Freedman

Hi Ken,

The macro you want to record is going to take several steps. With the recorder
running in a document that already contains one or more superscripted notations:

- Open the Find dialog. Click the More button and check "Use wildcards".
- Type the same expression in the Find What box as before, \[*\]
- Press Ctrl+Shift+= so the Format line below the box says Superscript.
- Click the Find Next button.
- Click the Close button.
- Press Ctrl and the right arrow key once to get to the beginning of the next
word.
- Press Ctrl+Shift and the right arrow key once to select the next word.
- Stop the recorder.

Assign this macro to a Quick Access Toolbar button or a keyboard shortcut.

If you meant to have the macro make the same formatting change to the first word
after each notation in the whole document, that's going to take some manual
modification of the macro; it can't be done with the recorder alone.

Actually, while I have you, would you mind giving me the wildcard
instructions for finding the first word after the superscripted notations I
referred to above. I'd like to record another macro to find the first word
after the notations (so that I can make some font changes, etc).

Thanks in advance!

Ken

Ken A. Dienne said:
Thanks - that's brilliant! :)

K

Jay Freedman said:
On Tue, 1 Apr 2008 18:05:00 -0700, Ken A. Dienne

OK, so I've searched everywhere, and read up on the websites for WORD 2007,
but I can't figure out how to set a repeated action to a shortcut key. I've
tried recording a macro, but it hasn't worked so far ... maybe I'm just not
doing it properly. Anyway, here's what I'd like to do:

I write long exercises for ESL textbooks, which include superscripted
notations (i.e. numbers inside brackets) in front of the answer blanks, and
I'd like to figure out a way for WORD to 'superscript all brackets and their
contents' at the press of a key or click of a button. Right now, I have to
highlight each bracket-number set individually, holding down 'control', and
then hit the 'superscript' button. It's the highlighting of multiple items
that drives me crazy ...

If anyone knows how I can set this up, I'd be very grateful for the tip.

Cheers!

K

Step 1: Recognize that the easiest way to do this is a wildcard search & replace
(http://www.gmayor.com/replace_using_wildcards.htm) in which the only difference
between the found text and the replacement text is the superscript formatting.
One click of the Replace All button will reformat every notation in the whole
document -- and doing it again and again won't change the ones that are already
superscript.

In this case, the Find What expression should be

\[*\]

Because the brackets have special meaning in a wildcard search, the backslashes
are needed to tell Word to search for actual brackets in the text. The asterisk
represents any characters that occur between left and right brackets.

The Replace With expression should be

^&

which is the code for "the same characters that were matched". While the cursor
is in the Replace With box. press Ctrl+Shift+= to apply Superscript formatting
(or go through the Format > Font button in the bottom left of the Replace dialog
and check the Superscript box).

Then click the Replace All button.

This can be recorded as a macro, which can be assigned to a button on the Quick
Access Toolbar or to a keyboard shortcut.
 
K

Ken A. Dienne

Hi, Jay:

Thanks for all your help! This is amazing - and truly helpful - stuff! (I'm
an editor, so I spend eight hours a day working with WORD.) Anyway, yes, I'd
like to figure out how to make format changes to the first word after each
notation in the entire document. If I can't do it with the recorder, I don't
think I'll bother, though, as I've never done any of this high-level tweaking
before ...

Thanks again!

Ken

Jay Freedman said:
Hi Ken,

The macro you want to record is going to take several steps. With the recorder
running in a document that already contains one or more superscripted notations:

- Open the Find dialog. Click the More button and check "Use wildcards".
- Type the same expression in the Find What box as before, \[*\]
- Press Ctrl+Shift+= so the Format line below the box says Superscript.
- Click the Find Next button.
- Click the Close button.
- Press Ctrl and the right arrow key once to get to the beginning of the next
word.
- Press Ctrl+Shift and the right arrow key once to select the next word.
- Stop the recorder.

Assign this macro to a Quick Access Toolbar button or a keyboard shortcut.

If you meant to have the macro make the same formatting change to the first word
after each notation in the whole document, that's going to take some manual
modification of the macro; it can't be done with the recorder alone.

Actually, while I have you, would you mind giving me the wildcard
instructions for finding the first word after the superscripted notations I
referred to above. I'd like to record another macro to find the first word
after the notations (so that I can make some font changes, etc).

Thanks in advance!

Ken

Ken A. Dienne said:
Thanks - that's brilliant! :)

K

:

On Tue, 1 Apr 2008 18:05:00 -0700, Ken A. Dienne

OK, so I've searched everywhere, and read up on the websites for WORD 2007,
but I can't figure out how to set a repeated action to a shortcut key. I've
tried recording a macro, but it hasn't worked so far ... maybe I'm just not
doing it properly. Anyway, here's what I'd like to do:

I write long exercises for ESL textbooks, which include superscripted
notations (i.e. numbers inside brackets) in front of the answer blanks, and
I'd like to figure out a way for WORD to 'superscript all brackets and their
contents' at the press of a key or click of a button. Right now, I have to
highlight each bracket-number set individually, holding down 'control', and
then hit the 'superscript' button. It's the highlighting of multiple items
that drives me crazy ...

If anyone knows how I can set this up, I'd be very grateful for the tip.

Cheers!

K

Step 1: Recognize that the easiest way to do this is a wildcard search & replace
(http://www.gmayor.com/replace_using_wildcards.htm) in which the only difference
between the found text and the replacement text is the superscript formatting.
One click of the Replace All button will reformat every notation in the whole
document -- and doing it again and again won't change the ones that are already
superscript.

In this case, the Find What expression should be

\[*\]

Because the brackets have special meaning in a wildcard search, the backslashes
are needed to tell Word to search for actual brackets in the text. The asterisk
represents any characters that occur between left and right brackets.

The Replace With expression should be

^&

which is the code for "the same characters that were matched". While the cursor
is in the Replace With box. press Ctrl+Shift+= to apply Superscript formatting
(or go through the Format > Font button in the bottom left of the Replace dialog
and check the Superscript box).

Then click the Replace All button.

This can be recorded as a macro, which can be assigned to a button on the Quick
Access Toolbar or to a keyboard shortcut.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.
 
J

Jay Freedman

Hi Ken,

This is what the macro should look like after "tweaking". You can replace
the Bold statement to apply whatever formatting you want the next word to
have. The loop will continue until it's done all the occurrences in the
document.

Sub demo()
Dim myRange As Range
Set myRange = ActiveDocument.Range

With myRange.Find
' Look for superscript text in brackets
.ClearFormatting
.Font.Superscript = True
.Text = "\[*\]"
.Replacement.Text = "^&"
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True

' Every time the text is found,
' make the next word bold:
Do While .Execute
myRange.Move Unit:=wdWord, Count:=1
myRange.MoveEnd Unit:=wdWord, Count:=1
myRange.Font.Bold = True ' <== this turns on bold
myRange.Collapse wdCollapseEnd
Loop
End With
End Sub


--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
Hi, Jay:

Thanks for all your help! This is amazing - and truly helpful -
stuff! (I'm an editor, so I spend eight hours a day working with
WORD.) Anyway, yes, I'd like to figure out how to make format changes
to the first word after each notation in the entire document. If I
can't do it with the recorder, I don't think I'll bother, though, as
I've never done any of this high-level tweaking before ...

Thanks again!

Ken

Jay Freedman said:
Hi Ken,

The macro you want to record is going to take several steps. With
the recorder
running in a document that already contains one or more
superscripted notations:

- Open the Find dialog. Click the More button and check "Use
wildcards".
- Type the same expression in the Find What box as before, \[*\]
- Press Ctrl+Shift+= so the Format line below the box says
Superscript.
- Click the Find Next button.
- Click the Close button.
- Press Ctrl and the right arrow key once to get to the beginning of
the next
word.
- Press Ctrl+Shift and the right arrow key once to select the next
word.
- Stop the recorder.

Assign this macro to a Quick Access Toolbar button or a keyboard
shortcut.

If you meant to have the macro make the same formatting change to
the first word
after each notation in the whole document, that's going to take some
manual
modification of the macro; it can't be done with the recorder alone.

Actually, while I have you, would you mind giving me the wildcard
instructions for finding the first word after the superscripted
notations I referred to above. I'd like to record another macro to
find the first word after the notations (so that I can make some
font changes, etc).

Thanks in advance!

Ken

:

Thanks - that's brilliant! :)

K

:

On Tue, 1 Apr 2008 18:05:00 -0700, Ken A. Dienne

OK, so I've searched everywhere, and read up on the websites for
WORD 2007, but I can't figure out how to set a repeated action
to a shortcut key. I've tried recording a macro, but it hasn't
worked so far ... maybe I'm just not doing it properly. Anyway,
here's what I'd like to do:

I write long exercises for ESL textbooks, which include
superscripted notations (i.e. numbers inside brackets) in front
of the answer blanks, and I'd like to figure out a way for WORD
to 'superscript all brackets and their contents' at the press of
a key or click of a button. Right now, I have to highlight each
bracket-number set individually, holding down 'control', and
then hit the 'superscript' button. It's the highlighting of
multiple items that drives me crazy ...

If anyone knows how I can set this up, I'd be very grateful for
the tip.

Cheers!

K

Step 1: Recognize that the easiest way to do this is a wildcard
search & replace
(http://www.gmayor.com/replace_using_wildcards.htm) in which the
only difference between the found text and the replacement text
is the superscript formatting. One click of the Replace All
button will reformat every notation in the whole document -- and
doing it again and again won't change the ones that are already
superscript.

In this case, the Find What expression should be

\[*\]

Because the brackets have special meaning in a wildcard search,
the backslashes are needed to tell Word to search for actual
brackets in the text. The asterisk represents any characters that
occur between left and right brackets.

The Replace With expression should be

^&

which is the code for "the same characters that were matched".
While the cursor is in the Replace With box. press Ctrl+Shift+=
to apply Superscript formatting (or go through the Format > Font
button in the bottom left of the Replace dialog and check the
Superscript box).

Then click the Replace All button.

This can be recorded as a macro, which can be assigned to a
button on the Quick Access Toolbar or to a keyboard shortcut.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
K

Ken A. Dienne

Hi, Jay:

Do I add this script to the bottom of the superscript macro I already
created? Or where else should I put it? Also, here's the formatting I'd like
to do:


change the font to Tekton
change the colour of the word to red
underline the word
change the colour of the underline to black

Thanks so much for your help with this! You've opened up a whole new facet
of WORD for me! :)

Ken

Jay Freedman said:
Hi Ken,

This is what the macro should look like after "tweaking". You can replace
the Bold statement to apply whatever formatting you want the next word to
have. The loop will continue until it's done all the occurrences in the
document.

Sub demo()
Dim myRange As Range
Set myRange = ActiveDocument.Range

With myRange.Find
' Look for superscript text in brackets
.ClearFormatting
.Font.Superscript = True
.Text = "\[*\]"
.Replacement.Text = "^&"
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True

' Every time the text is found,
' make the next word bold:
Do While .Execute
myRange.Move Unit:=wdWord, Count:=1
myRange.MoveEnd Unit:=wdWord, Count:=1
myRange.Font.Bold = True ' <== this turns on bold
myRange.Collapse wdCollapseEnd
Loop
End With
End Sub


--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
Hi, Jay:

Thanks for all your help! This is amazing - and truly helpful -
stuff! (I'm an editor, so I spend eight hours a day working with
WORD.) Anyway, yes, I'd like to figure out how to make format changes
to the first word after each notation in the entire document. If I
can't do it with the recorder, I don't think I'll bother, though, as
I've never done any of this high-level tweaking before ...

Thanks again!

Ken

Jay Freedman said:
Hi Ken,

The macro you want to record is going to take several steps. With
the recorder
running in a document that already contains one or more
superscripted notations:

- Open the Find dialog. Click the More button and check "Use
wildcards".
- Type the same expression in the Find What box as before, \[*\]
- Press Ctrl+Shift+= so the Format line below the box says
Superscript.
- Click the Find Next button.
- Click the Close button.
- Press Ctrl and the right arrow key once to get to the beginning of
the next
word.
- Press Ctrl+Shift and the right arrow key once to select the next
word.
- Stop the recorder.

Assign this macro to a Quick Access Toolbar button or a keyboard
shortcut.

If you meant to have the macro make the same formatting change to
the first word
after each notation in the whole document, that's going to take some
manual
modification of the macro; it can't be done with the recorder alone.

On Wed, 2 Apr 2008 16:30:00 -0700, Ken A. Dienne

Actually, while I have you, would you mind giving me the wildcard
instructions for finding the first word after the superscripted
notations I referred to above. I'd like to record another macro to
find the first word after the notations (so that I can make some
font changes, etc).

Thanks in advance!

Ken

:

Thanks - that's brilliant! :)

K

:

On Tue, 1 Apr 2008 18:05:00 -0700, Ken A. Dienne

OK, so I've searched everywhere, and read up on the websites for
WORD 2007, but I can't figure out how to set a repeated action
to a shortcut key. I've tried recording a macro, but it hasn't
worked so far ... maybe I'm just not doing it properly. Anyway,
here's what I'd like to do:

I write long exercises for ESL textbooks, which include
superscripted notations (i.e. numbers inside brackets) in front
of the answer blanks, and I'd like to figure out a way for WORD
to 'superscript all brackets and their contents' at the press of
a key or click of a button. Right now, I have to highlight each
bracket-number set individually, holding down 'control', and
then hit the 'superscript' button. It's the highlighting of
multiple items that drives me crazy ...

If anyone knows how I can set this up, I'd be very grateful for
the tip.

Cheers!

K

Step 1: Recognize that the easiest way to do this is a wildcard
search & replace
(http://www.gmayor.com/replace_using_wildcards.htm) in which the
only difference between the found text and the replacement text
is the superscript formatting. One click of the Replace All
button will reformat every notation in the whole document -- and
doing it again and again won't change the ones that are already
superscript.

In this case, the Find What expression should be

\[*\]

Because the brackets have special meaning in a wildcard search,
the backslashes are needed to tell Word to search for actual
brackets in the text. The asterisk represents any characters that
occur between left and right brackets.

The Replace With expression should be

^&

which is the code for "the same characters that were matched".
While the cursor is in the Replace With box. press Ctrl+Shift+=
to apply Superscript formatting (or go through the Format > Font
button in the bottom left of the Replace dialog and check the
Superscript box).

Then click the Replace All button.

This can be recorded as a macro, which can be assigned to a
button on the Quick Access Toolbar or to a keyboard shortcut.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
J

Jay Freedman

Hi Ken,

Although it would be possible to combine the two macros, I think it's better to
keep them as two separate macros with separate buttons that you can run when
needed.

In the VBA editor's Project pane, you'll see a tree diagram like the one in the
Windows Explorer. The top-level projects correspond to the open templates and
documents, with folders (Objects, Forms, Modules) and items inside those
folders.

If you recorded the superscript macro without changing anything in the recorder
dialog, then you'll find a NewMacros module inside the Modules folder of the
Normal project. Double-click it to open the code of your recorded macro on the
right side. Then paste the following code below the existing End Sub line.

Sub FormatNextWord()
Dim myRange As Range
Set myRange = ActiveDocument.Range

With myRange.Find
' Look for superscript text in brackets
.ClearFormatting
.Font.Superscript = True
.Text = "\[*\]"
.Replacement.Text = "^&"
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True

' Every time the text is found,
' make the next word bold:
Do While .Execute
myRange.Move Unit:=wdWord, Count:=1
myRange.MoveEnd Unit:=wdWord, Count:=1
' If the notation was at the end of a
' paragraph, need to move to the word
' after the paragraph mark.
If myRange.Characters(1).Text = vbCr Then
myRange.Collapse wdCollapseEnd
myRange.MoveEnd Unit:=wdWord, Count:=1
End If
myRange.Font.Name = "Tekton"
myRange.Font.Color = wdColorRed
myRange.Font.Underline = wdUnderlineSingle
myRange.Font.UnderlineColor = wdColorBlack
myRange.Collapse wdCollapseEnd
Loop
End With
End Sub


Hi, Jay:

Do I add this script to the bottom of the superscript macro I already
created? Or where else should I put it? Also, here's the formatting I'd like
to do:


change the font to Tekton
change the colour of the word to red
underline the word
change the colour of the underline to black

Thanks so much for your help with this! You've opened up a whole new facet
of WORD for me! :)

Ken

Jay Freedman said:
Hi Ken,

This is what the macro should look like after "tweaking". You can replace
the Bold statement to apply whatever formatting you want the next word to
have. The loop will continue until it's done all the occurrences in the
document.

Sub demo()
Dim myRange As Range
Set myRange = ActiveDocument.Range

With myRange.Find
' Look for superscript text in brackets
.ClearFormatting
.Font.Superscript = True
.Text = "\[*\]"
.Replacement.Text = "^&"
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True

' Every time the text is found,
' make the next word bold:
Do While .Execute
myRange.Move Unit:=wdWord, Count:=1
myRange.MoveEnd Unit:=wdWord, Count:=1
myRange.Font.Bold = True ' <== this turns on bold
myRange.Collapse wdCollapseEnd
Loop
End With
End Sub


--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
Hi, Jay:

Thanks for all your help! This is amazing - and truly helpful -
stuff! (I'm an editor, so I spend eight hours a day working with
WORD.) Anyway, yes, I'd like to figure out how to make format changes
to the first word after each notation in the entire document. If I
can't do it with the recorder, I don't think I'll bother, though, as
I've never done any of this high-level tweaking before ...

Thanks again!

Ken

:

Hi Ken,

The macro you want to record is going to take several steps. With
the recorder
running in a document that already contains one or more
superscripted notations:

- Open the Find dialog. Click the More button and check "Use
wildcards".
- Type the same expression in the Find What box as before, \[*\]
- Press Ctrl+Shift+= so the Format line below the box says
Superscript.
- Click the Find Next button.
- Click the Close button.
- Press Ctrl and the right arrow key once to get to the beginning of
the next
word.
- Press Ctrl+Shift and the right arrow key once to select the next
word.
- Stop the recorder.

Assign this macro to a Quick Access Toolbar button or a keyboard
shortcut.

If you meant to have the macro make the same formatting change to
the first word
after each notation in the whole document, that's going to take some
manual
modification of the macro; it can't be done with the recorder alone.

On Wed, 2 Apr 2008 16:30:00 -0700, Ken A. Dienne

Actually, while I have you, would you mind giving me the wildcard
instructions for finding the first word after the superscripted
notations I referred to above. I'd like to record another macro to
find the first word after the notations (so that I can make some
font changes, etc).

Thanks in advance!

Ken

:

Thanks - that's brilliant! :)

K

:

On Tue, 1 Apr 2008 18:05:00 -0700, Ken A. Dienne

OK, so I've searched everywhere, and read up on the websites for
WORD 2007, but I can't figure out how to set a repeated action
to a shortcut key. I've tried recording a macro, but it hasn't
worked so far ... maybe I'm just not doing it properly. Anyway,
here's what I'd like to do:

I write long exercises for ESL textbooks, which include
superscripted notations (i.e. numbers inside brackets) in front
of the answer blanks, and I'd like to figure out a way for WORD
to 'superscript all brackets and their contents' at the press of
a key or click of a button. Right now, I have to highlight each
bracket-number set individually, holding down 'control', and
then hit the 'superscript' button. It's the highlighting of
multiple items that drives me crazy ...

If anyone knows how I can set this up, I'd be very grateful for
the tip.

Cheers!

K

Step 1: Recognize that the easiest way to do this is a wildcard
search & replace
(http://www.gmayor.com/replace_using_wildcards.htm) in which the
only difference between the found text and the replacement text
is the superscript formatting. One click of the Replace All
button will reformat every notation in the whole document -- and
doing it again and again won't change the ones that are already
superscript.

In this case, the Find What expression should be

\[*\]

Because the brackets have special meaning in a wildcard search,
the backslashes are needed to tell Word to search for actual
brackets in the text. The asterisk represents any characters that
occur between left and right brackets.

The Replace With expression should be

^&

which is the code for "the same characters that were matched".
While the cursor is in the Replace With box. press Ctrl+Shift+=
to apply Superscript formatting (or go through the Format > Font
button in the bottom left of the Replace dialog and check the
Superscript box).

Then click the Replace All button.

This can be recorded as a macro, which can be assigned to a
button on the Quick Access Toolbar or to a keyboard shortcut.
 
K

Ken A. Dienne

Thanks a lot, Jay! You've been a big, big help! :)

Ken

Jay Freedman said:
Hi Ken,

Although it would be possible to combine the two macros, I think it's better to
keep them as two separate macros with separate buttons that you can run when
needed.

In the VBA editor's Project pane, you'll see a tree diagram like the one in the
Windows Explorer. The top-level projects correspond to the open templates and
documents, with folders (Objects, Forms, Modules) and items inside those
folders.

If you recorded the superscript macro without changing anything in the recorder
dialog, then you'll find a NewMacros module inside the Modules folder of the
Normal project. Double-click it to open the code of your recorded macro on the
right side. Then paste the following code below the existing End Sub line.

Sub FormatNextWord()
Dim myRange As Range
Set myRange = ActiveDocument.Range

With myRange.Find
' Look for superscript text in brackets
.ClearFormatting
.Font.Superscript = True
.Text = "\[*\]"
.Replacement.Text = "^&"
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True

' Every time the text is found,
' make the next word bold:
Do While .Execute
myRange.Move Unit:=wdWord, Count:=1
myRange.MoveEnd Unit:=wdWord, Count:=1
' If the notation was at the end of a
' paragraph, need to move to the word
' after the paragraph mark.
If myRange.Characters(1).Text = vbCr Then
myRange.Collapse wdCollapseEnd
myRange.MoveEnd Unit:=wdWord, Count:=1
End If
myRange.Font.Name = "Tekton"
myRange.Font.Color = wdColorRed
myRange.Font.Underline = wdUnderlineSingle
myRange.Font.UnderlineColor = wdColorBlack
myRange.Collapse wdCollapseEnd
Loop
End With
End Sub


Hi, Jay:

Do I add this script to the bottom of the superscript macro I already
created? Or where else should I put it? Also, here's the formatting I'd like
to do:


change the font to Tekton
change the colour of the word to red
underline the word
change the colour of the underline to black

Thanks so much for your help with this! You've opened up a whole new facet
of WORD for me! :)

Ken

Jay Freedman said:
Hi Ken,

This is what the macro should look like after "tweaking". You can replace
the Bold statement to apply whatever formatting you want the next word to
have. The loop will continue until it's done all the occurrences in the
document.

Sub demo()
Dim myRange As Range
Set myRange = ActiveDocument.Range

With myRange.Find
' Look for superscript text in brackets
.ClearFormatting
.Font.Superscript = True
.Text = "\[*\]"
.Replacement.Text = "^&"
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True

' Every time the text is found,
' make the next word bold:
Do While .Execute
myRange.Move Unit:=wdWord, Count:=1
myRange.MoveEnd Unit:=wdWord, Count:=1
myRange.Font.Bold = True ' <== this turns on bold
myRange.Collapse wdCollapseEnd
Loop
End With
End Sub


--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

Ken A. Dienne wrote:
Hi, Jay:

Thanks for all your help! This is amazing - and truly helpful -
stuff! (I'm an editor, so I spend eight hours a day working with
WORD.) Anyway, yes, I'd like to figure out how to make format changes
to the first word after each notation in the entire document. If I
can't do it with the recorder, I don't think I'll bother, though, as
I've never done any of this high-level tweaking before ...

Thanks again!

Ken

:

Hi Ken,

The macro you want to record is going to take several steps. With
the recorder
running in a document that already contains one or more
superscripted notations:

- Open the Find dialog. Click the More button and check "Use
wildcards".
- Type the same expression in the Find What box as before, \[*\]
- Press Ctrl+Shift+= so the Format line below the box says
Superscript.
- Click the Find Next button.
- Click the Close button.
- Press Ctrl and the right arrow key once to get to the beginning of
the next
word.
- Press Ctrl+Shift and the right arrow key once to select the next
word.
- Stop the recorder.

Assign this macro to a Quick Access Toolbar button or a keyboard
shortcut.

If you meant to have the macro make the same formatting change to
the first word
after each notation in the whole document, that's going to take some
manual
modification of the macro; it can't be done with the recorder alone.

On Wed, 2 Apr 2008 16:30:00 -0700, Ken A. Dienne

Actually, while I have you, would you mind giving me the wildcard
instructions for finding the first word after the superscripted
notations I referred to above. I'd like to record another macro to
find the first word after the notations (so that I can make some
font changes, etc).

Thanks in advance!

Ken

:

Thanks - that's brilliant! :)

K

:

On Tue, 1 Apr 2008 18:05:00 -0700, Ken A. Dienne

OK, so I've searched everywhere, and read up on the websites for
WORD 2007, but I can't figure out how to set a repeated action
to a shortcut key. I've tried recording a macro, but it hasn't
worked so far ... maybe I'm just not doing it properly. Anyway,
here's what I'd like to do:

I write long exercises for ESL textbooks, which include
superscripted notations (i.e. numbers inside brackets) in front
of the answer blanks, and I'd like to figure out a way for WORD
to 'superscript all brackets and their contents' at the press of
a key or click of a button. Right now, I have to highlight each
bracket-number set individually, holding down 'control', and
then hit the 'superscript' button. It's the highlighting of
multiple items that drives me crazy ...

If anyone knows how I can set this up, I'd be very grateful for
the tip.

Cheers!

K

Step 1: Recognize that the easiest way to do this is a wildcard
search & replace
(http://www.gmayor.com/replace_using_wildcards.htm) in which the
only difference between the found text and the replacement text
is the superscript formatting. One click of the Replace All
button will reformat every notation in the whole document -- and
doing it again and again won't change the ones that are already
superscript.

In this case, the Find What expression should be

\[*\]

Because the brackets have special meaning in a wildcard search,
the backslashes are needed to tell Word to search for actual
brackets in the text. The asterisk represents any characters that
occur between left and right brackets.

The Replace With expression should be

^&

which is the code for "the same characters that were matched".
While the cursor is in the Replace With box. press Ctrl+Shift+=
to apply Superscript formatting (or go through the Format > Font
button in the bottom left of the Replace dialog and check the
Superscript box).

Then click the Replace All button.

This can be recorded as a macro, which can be assigned to a
button on the Quick Access Toolbar or to a keyboard shortcut.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.
 
K

Ken A. Dienne

Sorry to bug you again, Jay. I tried your suggestion, but for some reason,
the macro doesn't work (it works for the superscripting, but not for the
formating of the words directly after the superscripted brackets). I think
the problem is that I have a space between the superscripted brackets and the
word. Is there any way to write the space into the macro?

Cheers!

Ken

Ken A. Dienne said:
Thanks a lot, Jay! You've been a big, big help! :)

Ken

Jay Freedman said:
Hi Ken,

Although it would be possible to combine the two macros, I think it's better to
keep them as two separate macros with separate buttons that you can run when
needed.

In the VBA editor's Project pane, you'll see a tree diagram like the one in the
Windows Explorer. The top-level projects correspond to the open templates and
documents, with folders (Objects, Forms, Modules) and items inside those
folders.

If you recorded the superscript macro without changing anything in the recorder
dialog, then you'll find a NewMacros module inside the Modules folder of the
Normal project. Double-click it to open the code of your recorded macro on the
right side. Then paste the following code below the existing End Sub line.

Sub FormatNextWord()
Dim myRange As Range
Set myRange = ActiveDocument.Range

With myRange.Find
' Look for superscript text in brackets
.ClearFormatting
.Font.Superscript = True
.Text = "\[*\]"
.Replacement.Text = "^&"
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True

' Every time the text is found,
' make the next word bold:
Do While .Execute
myRange.Move Unit:=wdWord, Count:=1
myRange.MoveEnd Unit:=wdWord, Count:=1
' If the notation was at the end of a
' paragraph, need to move to the word
' after the paragraph mark.
If myRange.Characters(1).Text = vbCr Then
myRange.Collapse wdCollapseEnd
myRange.MoveEnd Unit:=wdWord, Count:=1
End If
myRange.Font.Name = "Tekton"
myRange.Font.Color = wdColorRed
myRange.Font.Underline = wdUnderlineSingle
myRange.Font.UnderlineColor = wdColorBlack
myRange.Collapse wdCollapseEnd
Loop
End With
End Sub


Hi, Jay:

Do I add this script to the bottom of the superscript macro I already
created? Or where else should I put it? Also, here's the formatting I'd like
to do:


change the font to Tekton
change the colour of the word to red
underline the word
change the colour of the underline to black

Thanks so much for your help with this! You've opened up a whole new facet
of WORD for me! :)

Ken

:

Hi Ken,

This is what the macro should look like after "tweaking". You can replace
the Bold statement to apply whatever formatting you want the next word to
have. The loop will continue until it's done all the occurrences in the
document.

Sub demo()
Dim myRange As Range
Set myRange = ActiveDocument.Range

With myRange.Find
' Look for superscript text in brackets
.ClearFormatting
.Font.Superscript = True
.Text = "\[*\]"
.Replacement.Text = "^&"
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True

' Every time the text is found,
' make the next word bold:
Do While .Execute
myRange.Move Unit:=wdWord, Count:=1
myRange.MoveEnd Unit:=wdWord, Count:=1
myRange.Font.Bold = True ' <== this turns on bold
myRange.Collapse wdCollapseEnd
Loop
End With
End Sub


--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

Ken A. Dienne wrote:
Hi, Jay:

Thanks for all your help! This is amazing - and truly helpful -
stuff! (I'm an editor, so I spend eight hours a day working with
WORD.) Anyway, yes, I'd like to figure out how to make format changes
to the first word after each notation in the entire document. If I
can't do it with the recorder, I don't think I'll bother, though, as
I've never done any of this high-level tweaking before ...

Thanks again!

Ken

:

Hi Ken,

The macro you want to record is going to take several steps. With
the recorder
running in a document that already contains one or more
superscripted notations:

- Open the Find dialog. Click the More button and check "Use
wildcards".
- Type the same expression in the Find What box as before, \[*\]
- Press Ctrl+Shift+= so the Format line below the box says
Superscript.
- Click the Find Next button.
- Click the Close button.
- Press Ctrl and the right arrow key once to get to the beginning of
the next
word.
- Press Ctrl+Shift and the right arrow key once to select the next
word.
- Stop the recorder.

Assign this macro to a Quick Access Toolbar button or a keyboard
shortcut.

If you meant to have the macro make the same formatting change to
the first word
after each notation in the whole document, that's going to take some
manual
modification of the macro; it can't be done with the recorder alone.

On Wed, 2 Apr 2008 16:30:00 -0700, Ken A. Dienne

Actually, while I have you, would you mind giving me the wildcard
instructions for finding the first word after the superscripted
notations I referred to above. I'd like to record another macro to
find the first word after the notations (so that I can make some
font changes, etc).

Thanks in advance!

Ken

:

Thanks - that's brilliant! :)

K

:

On Tue, 1 Apr 2008 18:05:00 -0700, Ken A. Dienne

OK, so I've searched everywhere, and read up on the websites for
WORD 2007, but I can't figure out how to set a repeated action
to a shortcut key. I've tried recording a macro, but it hasn't
worked so far ... maybe I'm just not doing it properly. Anyway,
here's what I'd like to do:

I write long exercises for ESL textbooks, which include
superscripted notations (i.e. numbers inside brackets) in front
of the answer blanks, and I'd like to figure out a way for WORD
to 'superscript all brackets and their contents' at the press of
a key or click of a button. Right now, I have to highlight each
bracket-number set individually, holding down 'control', and
then hit the 'superscript' button. It's the highlighting of
multiple items that drives me crazy ...

If anyone knows how I can set this up, I'd be very grateful for
the tip.

Cheers!

K

Step 1: Recognize that the easiest way to do this is a wildcard
search & replace
(http://www.gmayor.com/replace_using_wildcards.htm) in which the
only difference between the found text and the replacement text
is the superscript formatting. One click of the Replace All
button will reformat every notation in the whole document -- and
doing it again and again won't change the ones that are already
superscript.

In this case, the Find What expression should be

\[*\]

Because the brackets have special meaning in a wildcard search,
the backslashes are needed to tell Word to search for actual
brackets in the text. The asterisk represents any characters that
occur between left and right brackets.

The Replace With expression should be

^&

which is the code for "the same characters that were matched".
While the cursor is in the Replace With box. press Ctrl+Shift+=
to apply Superscript formatting (or go through the Format > Font
button in the bottom left of the Replace dialog and check the
Superscript box).

Then click the Replace All button.

This can be recorded as a macro, which can be assigned to a
button on the Quick Access Toolbar or to a keyboard shortcut.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.
 
J

Jay Freedman

I tried this macro on a document where I had inserted some numbers in brackets,
which had been superscripted. It works the same whether there are or aren't
spaces -- any number of spaces -- before or after the bracketed items. I don't
think that has anything to do with it.

However, I do think there's something in your document that I don't know about,
and that the macro isn't taking into account. Can you copy a chunk of your
document into a new blank document and email it to me?

Sorry to bug you again, Jay. I tried your suggestion, but for some reason,
the macro doesn't work (it works for the superscripting, but not for the
formating of the words directly after the superscripted brackets). I think
the problem is that I have a space between the superscripted brackets and the
word. Is there any way to write the space into the macro?

Cheers!

Ken

Ken A. Dienne said:
Thanks a lot, Jay! You've been a big, big help! :)

Ken

Jay Freedman said:
Hi Ken,

Although it would be possible to combine the two macros, I think it's better to
keep them as two separate macros with separate buttons that you can run when
needed.

In the VBA editor's Project pane, you'll see a tree diagram like the one in the
Windows Explorer. The top-level projects correspond to the open templates and
documents, with folders (Objects, Forms, Modules) and items inside those
folders.

If you recorded the superscript macro without changing anything in the recorder
dialog, then you'll find a NewMacros module inside the Modules folder of the
Normal project. Double-click it to open the code of your recorded macro on the
right side. Then paste the following code below the existing End Sub line.

Sub FormatNextWord()
Dim myRange As Range
Set myRange = ActiveDocument.Range

With myRange.Find
' Look for superscript text in brackets
.ClearFormatting
.Font.Superscript = True
.Text = "\[*\]"
.Replacement.Text = "^&"
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True

' Every time the text is found,
' make the next word bold:
Do While .Execute
myRange.Move Unit:=wdWord, Count:=1
myRange.MoveEnd Unit:=wdWord, Count:=1
' If the notation was at the end of a
' paragraph, need to move to the word
' after the paragraph mark.
If myRange.Characters(1).Text = vbCr Then
myRange.Collapse wdCollapseEnd
myRange.MoveEnd Unit:=wdWord, Count:=1
End If
myRange.Font.Name = "Tekton"
myRange.Font.Color = wdColorRed
myRange.Font.Underline = wdUnderlineSingle
myRange.Font.UnderlineColor = wdColorBlack
myRange.Collapse wdCollapseEnd
Loop
End With
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top