Macro Keyboard Shortcut

M

Me

In Word 2003, how do I assign a keyboard shortcut to an already existing macro?

Thank you.
 
J

John

Tools/Customise.../Keyboard...

then select "Macros" from the left-hand listbox.

You can then select the correct macro and change its shortcut key.

Best regards

John
 
J

Jason

Is there any VBA code that will do this? I would like to export a VBA file
and import to various PC's and not have to assign the key on every PC via the
Word menus. Is this possible?

Thanks,

Jason
 
J

John

Hello Jason,

Lookup the "Keybindings" object in Help. The example below is adapted from
that and seems to works ok.

Best regards

John

Sub Key()
'This example assigns the CTRL+SHIFT+B key
'combination to another procedure command
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyControl, _
wdKeyShift, wdKeyB), KeyCategory:=wdKeyCategoryCommand, _
Command:="MyFoundProcedure"
End Sub

Sub MyFoundProcedure()
MsgBox ("Found")
End Sub
 
J

Jason

Thanks, John. I guess that I should have stated that I already tried this.
Here is a copy of the code that I am using (this is in Word 97 if that
matters):

Sub LHAssignKey()
CustomizationContext = NormalTemplate
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyF11), _
KeyCategory:=wdKeyCategoryCommand, Command:="LetterHead"
End Sub

Sub LetterHead()
With ActiveDocument.PageSetup
.LeftMargin = Application.InchesToPoints(1)
.RightMargin = Application.InchesToPoints(1)
.TopMargin = Application.InchesToPoints(1.25)
.BottomMargin = Application.InchesToPoints(0.75)
.HeaderDistance = Application.InchesToPoints(0.25)
.FooterDistance = Application.InchesToPoints(0.25)
.DifferentFirstPageHeaderFooter = True
.SectionStart = wdSectionNewPage
End With
ActiveDocument.Sections(1).Headers_
(wdHeaderFooterFirstPage).Shapes.AddPicture _
("N:\Provider Audit\Templates\MISC\ugsheader.jpg")
ActiveDocument.Sections(1).Footers_
(wdHeaderFooterFirstPage).Shapes.AddPicture _
("N:\Provider Audit\Templates\MISC\ugsfooter.jpg")
If ActiveDocument.Range.Font.Size > 10 Then
Else
Selection.WholeStory
ActiveDocument.Range.Font.Size = 11
Selection.HomeKey Unit:=wdStory
End If
End Sub
 
C

Charles Kenyon

Didn't read the first post. Generally you do _not_ want normal.dot to be
your customization context. It makes your procedure look and feel a lot like
a virus to most users.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide




--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
J

Jason

Ok, well, even if I remove that line of code, it does not work. Any other
suggestions?

Thanks,

Jason
 
C

Charles Kenyon

Removing that line from your code leaves normal.dot, the default, as your
customization context.
This, though, is not the problem you wrote about and I have no advice on
that.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide




--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 

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