Good keybinding code no longer works - why?

J

Julian

Hi,

I have a quite large Word XP/2002 VBA project and it suffers badly from
bloat very quickly, so I rebuilt Normal.dot from a blank document (manually
using the organizer because of the limitations on copying from Normal.dot in
code) to make it smaller again.

However, my keybinding assignment code, which worked perfectly well before
the rebuild [i.e. I have the right context, the keybuild codes are fine, and
the new key assignments actually work] gives me "word cannot change the
function of the specified key" on every assignment

I can do it manually; I have recorded the manual reassignment and replayed
that - and I get the same error; I can clear the assignment perfectly well...
but I can't make the assignment in code anymore.

I've checked everything I can think of (References are the same and in the
same order, project compiles) - what have I missed?

Thoughts? Help *much*appreciated

Julian

PS The inoffensive but offending code looks like this...

CustomizationContext = NormalTemplate
keyBindings.add KeyCode:=BuildKeyCode(wdKeyA, wdKeyAlt),
KeyCategory:=wdKeyCategoryMacro,
Command:="Normal.Comment_Handling.markAlternate"

PPS Running in Vista HP... but it has been OK for ages
 
L

Lene Fredborg

As I understand your description of how you created the new Normal.dot, you
created a document, copied your macros etc. from the old Normal.dot to the
new document and saved it as Normal.dot. Is this correct? In that case, this
method could be part of the problem. You cannot create Normal.dot - you need
to let Word create it. To do this, exit Word, find and rename your old
Normal.dot (e.g. NormalOLD.dot). Restart Word - this forces Word to create a
new Normal.dot. Then you can copy macros etc. from NormalOLD.dot to that new
Normal.dot.

It may alto be an idea to clean your code using the free add-in "Code
Cleaner" that can be downloaded from:
http://www.word.mvps.org/FAQs/MacrosVBA/TemplateBloat.htm

--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 
J

Julian

Thanks Lene,

Didn't know that about creating Normal.dot - thanks that should deal with
everything.

BTW, I've grabbed the codecleaner, and I'll try it out, but I had written my
own project cleaner anyway to handle forms, styles and code... just doesn't
work at the moment because everything is in Normal (see below)

Decided to do this as I understand that just "cleaning up" the VBA isn't
everything when one has toolbars*, keybinding customisations etc. ... which
is why I wanted to start from a blank slate... but now I know I should let
word create Normal and then give it everything I require it's all clear.

Ideally I should place all my customisations in another template as an
add-in then I can use organizerdelete and organizercopy to rebuild it... but
annoyingly the the restrictions on organizercopy etc. introduced with Word97
SP1 are not explicitly referenced to subsequent versions but seem nonetheless
to apply. (see MS kb under 170267 under "wordbasic macrocopy command fails")

Anyway thanks for a quick simple and helpful reply,

Julian

* toolbars seem to accumulate (in an unfriendly hidden way) when/if created
as temporary and deleted at exit - had to give up on being neat and tidy like
that and make permanent toolbars...
 
R

Russ

Julian,
I think most people in this forum would suggest not leaving the bulk of your
customizations in Normal.dot, so that you could easily have Word regenerate
it again like Lene suggested. Instead move anything like your special menus,
toolbars, macros into a separate template or .dot file or multiple .dot
files that you can put into the Startup directories of Word and Office to
make them Global (always there when you start Word) or make them Local that
you attach through code to documents or put in the other Template drawers
that open when you use File/Open/New...the Project Gallery of Templates.
In other words, don't mess with Normal.dot, especially when you are
distributing macros to other people. You don't want to mess with their
Normal.dot settings, which they won't expect.
http://word.mvps.org/faqs/macrosvba/DistributeMacros.htm
 

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