Code Cleaner deleting keystroke assignments

L

Larry

Last night I made a copy of my Normal template and ran the Code Cleaner
on it. I checked it out afterward, running some macros and so on, to
make sure it was ok. It seemed fine and I renamed it as Normal. Then
today I saw that some keystroke assignments had been lost . So I went
back to the pre-cleaned version of the Normal.

This is tricky stuff. I have a couple of hundred keystroke assignments
in my Normal template, and I can't check all of them every time I run
Code Cleaner. I'm wondering how to verify that a cleaned template is
100 percent intact?

Larry
 
D

Doug Robbins - Word MVP

It will let you copy the key assignments from the pre-cleaned template to
the cleaned one.

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
L

Larry

I'm not asking HOW to copy all the key assignments. I was asking how to
determine WHETHER any key assignments were lost.

Also, copying key assignments with the Shortcut Organizer is a long
process because you have to copy the assignments one at a time and, as I
said, I have hundreds of key assignments.

Larry
 
P

Peter Hewett

Hi Larry

The reason the keystroke assignments disappear is that the keystrokes are bound to macros
in your template. To do it's business "Code Cleaner" exports/removes/imports *all*
modules in your project. When Code Cleaner remove a module it looks like the keystroke
assignments bound to any macros in that module disappear as well. Which when you think
about it all seems quite reasonable.

You could write a shitload of code to do a compare of the current template against an
earlier version of the template. But the code's going to be tricky to work correctly.

The other approach, which you may initially rebel at but is robust and durable, is to
create a procedure to setup the keyboard assignments for all of your macros. This is the
path I take with my Add-Ins, this way I can trigger the code when the Add-In loads.

HTH + Cheers - Peter
 
C

Charles Kenyon

I guess it doesn't. The Code Cleaner is a hack, a good hack. It doesn't do
everything.
 
L

Larry

So far there seems to be no way to know if keystrokes were lost. That's
a major bummer, which leads to Peter's idea of using a macro that
automatically re-creates key assignments after using Code Cleaner.

What would such a macro look like? And would the macro have to be
edited every time you change a key assignment? Or is there another
macro that creates the first macro, i.e., that goes through a template
and creates a macro that would re-assign all the existing key
assignments?

Larry
 
L

Larry

However, I realize I already have a partial solution to my question, but
forgot about it. I have a macro which prints a list of all the
keystrokes assigned to the macros in my Normal template. So, I can just
run that macro after doing a Code Clean and see if any key assignments
are missing.

The problem with this is that it's not possible to do the same thing
with my global add-in template, where I also have many macros with
keystrokes. This is because the keystroke assignments are in the Normal
template, while the macro is in the Global template, so there's no way
simply to return the keystroke assignments of the macros in the Global.
A solution would be to keep all my macros that have key assignments in
Normal, while I put all other macros, which have menu buttons rather
than keystrokes, in the Global.

Larry
 
L

Larry

Not quite. The macro only prints macros to which keystrokes have been
assigned, so if a key assignment has been dropped, the macro would
simply not appear and there would be no immediate way of knowing about
the dropped assignment.
 
L

Larry

I could run the macro that prints my key assignments before doing Code
Cleaner, then use WordCount to get the number of lines printed by that
macro, then run the macro again after doing Code Cleaner, and if the
number of lines has decreased, then I know that Code Cleaner has been
naughty.

Larry
 
L

Larry

Even better, I can simply run this macro before and after running Code
Cleaner:

Dim i As Long
i = 0
CustomizationContext = NormalTemplate
For Each aKey In KeyBindings
i = i + 1
Next aKey
MsgBox "There are " & i & " key assignments in Normal."
 
P

Peter Hewett

Hi Larry

Now you know why I said a shitload of code. Which ever way out of this situation you look
at it's convoluted! I don't know whether the <Chris Woodman's shortcut organizer>
mentioned by Charles earlier in the thread in unlocked but if it is that may provide a
source of some code and ideas.

Good luck! - Peter

I could run the macro that prints my key assignments before doing Code
Cleaner, then use WordCount to get the number of lines printed by that
macro, then run the macro again after doing Code Cleaner, and if the
number of lines has decreased, then I know that Code Cleaner has been
naughty.

Larry

HTH + Cheers - Peter
 
L

Larry

The reason the keystroke assignments disappear is that the keystrokes are bound to macros
in your template. To do it's business "Code Cleaner" exports/removes/imports *all*
modules in your project. When Code Cleaner remove a module it looks like the keystroke
assignments bound to any macros in that module disappear as well. Which when you think
about it all seems quite reasonable.

By your thinking, the keystrokes would never survive Code Cleaner, which
is obviously not the case. The bad stuff only happens occasionally.

Larry
 
P

Peter Hewett

Hi Larry

Irrespective of whether it happens consistently or inconsistently (even worse) you know
what the solution is. I'm sorry but I don't have the time to investigate this properly
(in depth), so I'm stating my expectations: Why should a reference to something that no
longer exists survive? It's certainly consistent (at least in part) with my own
observations and experiences.

HTH + Cheers - Peter
 
L

Larry

Well, this leads us back to your solution. You said:
The other approach, which you may initially rebel at but is robust and
durable, is to
create a procedure to setup the keyboard assignments for all of your
macros. This is the
path I take with my Add-Ins, this way I can trigger the code when the
Add-In loads.

Can you share this macro with us, or enough of it to get the idea? The
only difference is that I would want a macro that does this for Normal
as well as for an add-in.

Larry
 
P

Peter Hewett

Hi Larry

It's nothing but a whole lot of assignment statements, that's why I didn't post it!

But it goes like this:

' Bind the Ctrl+N key to the FileNewDefault procedure
KeyBindings.Add wdKeyCategoryMacro, "FileNewDefault", _
BuildKeyCode(wdKeyN, wdKeyControl)

' Bind the Alt+P key to the PrintCurrentPage procedure
KeyBindings.Add wdKeyCategoryMacro, "PrintCurrentPage", _
BuildKeyCode(wdKeyP, wdKeyAlt)

If you're running the code from an addin don't forget to set the CustomizationContext.

HTH + Cheers - Peter
 
L

Larry

Ok, thanks. I guess I was hoping there might be some super-magical way
of creating a macro that would re-assign the existing assignments, in
other words, it would go through all the existing key assignments and
print them out in the form of the code that you provide below. Creating
separate code for each assignment is a tall order in my case, as I have
.... well, I don't want to tell you how many customized key assignments I
have in Normal, because you'll think I'm nuts. :)

However, I'm thinking I might be able to create a macro to do what I
describe above ...

Larry
 

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