MACRO TO TOGGLE FONT ON AND OFF

J

JBusby

I have document that uses a particular font (usually no more than a few
characters in length) in numerous places throughout. Is there a macro that
would toggle this font on and off using a shortcut-key combination (e.g.
like the way that CTRL + "I" does for italic type)?
 
G

Gregory K. Maxey

If the original text is drafted using a style then I would assign something
like FontSwap to a keyboard shortcut:

Sub FontSwap()
If Not Selection.Font.Name = "Arial" Then
Selection.Font.Name = "Your Font Name"
Else
Selection.Font.Reset
End If
End Sub

If not, I would use something like:

If Not Selection.Font.Name = "Arial" Then
Selection.Font.Name = "Your Font Name"
Else
Selection.Font.Name = "Your defaultparagraphfont name"
End If
End Sub
 
J

JBusby

Hello Greg, and thanks for your response.
I'm having only limited success with the macros (having tried both of them).

I faced two problems:

1. Using the "Normal" Style, I applied "Fontswap" to a keyboard shortcut
and the
result was what I expected. But, I was unable, using the same keyboard
shortcut,
to return to the original font (Cambria body) after typing the "Fontswap"
characters (Old English Text MT).

2. The other problem occurred when I tried to create a macro using the
"Macros" button, on the Developer Tab, in the Code Group (Word 2007). After
naming the macro ("FontSwap"), I created a keyboard shortcut from the Quick
Access Toolbar by clicking "Macros" in the "Choose Commands From" dialogue
box, and completed the steps. However, when I tried to use the custom
keyboard shortcut in the actual document I got a pop-up that said, "You are
about to add a digital signature to this document. . ." When I "signed" it,
the document wouldn't allow anything further to happen! If I tried to type
anything at all the Status Bar said, "This modification is not allowed
because the selection is locked." Gee Whiz!
So I recorded a macro instead (in a new test document), assigned the
keyboard shortcut, paused the recorder, pasted the code, and it worked, for
the most part, as previously described (above).
So I probably did something wrong...right? Help?
 
G

Gregory K. Maxey

J,

Both work here without issues. If you will send you e-mail address I will
send you a template with Fontswap assigned shortcut Alt+f,s
 
J

JBusby

Thanks, Greg.
I appreciate your efforts on this.
One other question: What does the first line of code do? Why is "Arial" there?
(e-mail address removed)
 
G

Gregory K. Maxey

"Arial" is there simply because that is the font I selected to use in the
font swap during my test. My default paragraph font is "Times New Roman"
when I toggle the macro the font shifts between Times New Roman and Arial.
But, I see now that what I posted is confusing. It should read:

I can see now why the code worked the first time but then quit. Sorry.
 
J

JBusby

That got it! Thanks!
But I'm still finding it necessary to create the macro keyboard shortcut by
means of a "Record Macro" procedure (mentioned earlier) in order to avoid
getting a pop-up that says, "You are about to add a digital signature to this
document."
This seems to happen when I create the macro, and then, in a separate
process, create the keyboard shortcut from the "Customize the Quick Access
Toolbar and keyboard shortcuts" Dialogue Box.
It does that when I run the macro in the active document.
 
G

Gregory K. Maxey

You don't need to record a macro. Just insert a standard project module.
Copy the code to the module and then use the Keyboard shortcuts to set a
shortcut to that modue and procedure name.
 
J

JBusby

Thanks again. Everything is "ship-shape" now! I just had a problem finding my
way to the right place in the keyboard shortcut dialogue box when I created
my shortcut.
P.S. Finding some good stuff too, at your "Microsoft Word Help and Tips
Pages" (http://gregmaxey.mvps.org).
 

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