PDA

View Full Version : Solved: Keyboard shortcuts -- desperate now!



dmkitz
11-13-2006, 11:09 AM
:banghead: Please help - I'm starting to panic. In Word 2000. What code do I need to assign a Style to a keyboard shortcut? That appears to be the only way I can share the shortcuts with others. Thank you.

lucas
11-13-2006, 01:36 PM
I used the recorder to come up with this.....text style. MyStyle is the name of the style

Sub Macro1()
Selection.WholeStory
Selection.Style = ActiveDocument.Styles("MyStyle")
End Sub


I'm not sure what your trying to do???

mdmackillop
11-13-2006, 03:48 PM
This will assign the key combination Alt + N to the style Heading 1. Check Help for Keybindings


Sub MacroStyleKey()
CustomizationContext = NormalTemplate
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyN, wdKeyAlt), KeyCategory:= _
wdKeyCategoryStyle, Command:="Heading 1"
End Sub

dmkitz
11-13-2006, 04:09 PM
I'm sorry for not being specific. I am sharing documents that contain keyboard shortcuts assigned to styles. The styles are making the jump to the shared documents but when someone opens the file on their own computer, they don't have my keyboard shortcuts, of course. Is there a way to write the keyboard shortcuts into the code of the Word file? (Word 2000). Thanks.

fumei
11-13-2006, 04:12 PM
CustomizationContext = ActiveDocument.AttachedTemplate
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyJ, wdKeyAlt), _
KeyCategory:=wdKeyCategoryStyle, Command:="MyNewStyle"sets the keyboard shortcut Alt-J to the style MyNewStyle.

This works for any document as long as the applicable active template is available. If the active template file is not available there is an error. Also, as this does in fact change the template file itself, you do get a save warning. If you do not click Yes, the change (the keyboard shortcut) is not saved.

fumei
11-13-2006, 04:23 PM
Darn.....

Although you did not make a note that it can be used for any template, not just normal.dot.

...but....darn....
I am sharing documents that contain keyboard shortcuts assigned to styles. The styles are making the jump to the shared documents but when someone opens the file on their own computer, they don't have my keyboard shortcuts, of course. Is there a way to write the keyboard shortcuts into the code of the Word file? (Word 2000). Yes...you have it now.

To save keyboard shortcuts to a document, but not the template, use:CustomizationContext = ActiveDocumentNormally, keyboard shortcuts are assigned to the attached template. They can, however, be assigned to a document. So...assign them.

Since I have no idea what you are doing regarding the use of templates....

You can pass on keyboard shortcuts if they are in the document, not the template. However...you can have issues if the other person does not have the template file.

dmkitz
11-13-2006, 08:57 PM
I'm sorry but I'm not understanding your directions. If I write a sub, how will it be called? This is my project: I created several Word mail merge main documents to share with other users. They are not templates, but simple Word files. The custom Styles I created in the main documents are present in the Word file that results from the merge operation. I would like keyboard shortcuts (assigned to the custom styles) also to be present in the file that results from the merge operation.

fumei
11-13-2006, 10:39 PM
I understood what you wanted.

Call it whenever you want to call it. You do not describe exactly what you are doing, so I can't tell you when to call it. Shrug...when the document is closed? Use the Document_Close event.

You mention "several" documents - are you doing this at the same time?

Are you splitting the merged document into smaller documents?

I don't know.

The point is, shortcuts are file specific. Any shortcuts in a main merge document are NOT passed. Shortcuts are file specific.

So you have to make the shortcuts in the files. Which you know.

The code to do so is above.

When you do it, is up to you. Obviously though, you will run it after the merge, applying it to the new document. Come to think of it, no...you don't want to put it in as Document_Close. That would mean you have to actually write the procedure into the new document...pain in the butt.

Write the procedure and put it either in the main merge document, or in normal.dot. Fire it from there. If you have it in the main merge document, make sure you are actioning against the correct document. Firing it from the main merge file will make that file the ActiveDocument, soCustomizationContext = ActiveDocument would not be actioning the new document.

After you have saved the new document, you could then action it by name.

You could action against all open documents. The main merge document would get actioned as well, but who cares? You would have to make sure you had no open documents that you do NOT want these shortcuts in.

If the final (saved) documents are all in the same folder you could action against all the files there.

Whatever.

mdmackillop
11-18-2006, 03:42 AM
Hi dmkitz
Any feedback? Is this solved?
Regards
MD

dmkitz
11-19-2006, 10:21 AM
For various reasons I decided to solve it by writing a section in the instructional handout on how to create your own keyboard shortcuts and the benefits of using them. Part of it was the lack of time and energy I had to devote to the project and part was the old "give a man a fish versus teach a man how to fish" truth, plus I began to wonder how much time I wanted to spend on something written on Office 2000. Thanks for your help.

dmkitz
11-19-2006, 10:22 AM
I tried twice to mark this solved but my computer hangs up. Please do so for me. THanks.

lucas
11-19-2006, 10:25 AM
marked solved...