autoexec in add-in?

M

mmalinsky

I have the following code in an add-in. I've been having problems
with the key binding so I added an autoexec routine which I thought
would clear out the binding value when the add-in was loaded, but that
does not appear to be the case. I tested this by trying to get a
msgbox to pop-up when the add-in was loaded when Word was loaded and
nothing happened. Is there any way to get this to work?

Thanks,
Mike

Option Explicit

Sub AutoExec()

FindKey(BuildKeyCode(wdKeyNumericDecimal)).Clear
MsgBox FindKey(BuildKeyCode(wdKeyNumericDecimal)).KeyCategory

End Sub

Private Sub AssignNumpadPeriodToComma()

Dim SavedState As Boolean

SavedState = ThisDocument.Saved

If FindKey(BuildKeyCode(wdKeyNumericDecimal)).KeyCategory = -1
Then
CustomizationContext = NormalTemplate
KeyBindings.Add KeyCategory:=wdKeyCategoryMacro, _
KeyCode:=BuildKeyCode(wdKeyNumericDecimal), _
Command:="TypeAComma"
CommandBars("Helpers").Controls(1).State = msoButtonDown
Else
If FindKey(BuildKeyCode(wdKeyNumericDecimal)).KeyCategory = 2
Then
FindKey(BuildKeyCode(wdKeyNumericDecimal)).Clear
CommandBars("Helpers").Controls(1).State = msoButtonUp
End If
End If

StatusBar = FindKey(BuildKeyCode(wdKeyNumericDecimal)).KeyCategory

ThisDocument.Saved = SavedState

End Sub

Sub TypeAComma()

Selection.TypeText ","

End Sub
 
T

Tony Jollans

Are you saying the AutoExec doesn't run at all? And you have this in your
Startup folder?
 
M

mmalinsky

Actually, I just stumbled upon a new detail. This is a work computer
which has an third-party application that integrates with Word. This
third-party application, simply put, is a document organizer - a type
of paperless solution, if you will. The third-party application also
includes a Word add-in. When I open a Word document from outside of
the third-party app, my autoexec works fine. When I open a Word
document from within the third-party app, the autoexec does not fire.
I'm assuming it has something to do with the add-in related to third-
party app, which is password protected, so I cannot view it.

So the question I have now, is how can I ensure that my autoexec code
fires regardless of what other add-ins are doing, or am I just out of
luck?

Thanks.
 
Z

zkid

It's very typical behavior for document management programs to shut off
autoexec. In fact, generally, they shut off all of the auto executable subs
(autoopen, autoclose, etc.) This is necessary so they can control how
documents are being opened and saved (commonly referred to as hooking).

Now to tackle your problem:

Please summarize for us in a couple of sentences what exactly it is you need
to accomplish with your keybindings, and we'll see if there's another way to
go about it.

Thanks.
 
T

Tony Jollans

Actually, rather than it being the DMS, it is, I believe, Word that doesn't
run automacros when started via automation.
 
Z

zkid

Actually, I have a lot of experience with this. DMS's have Word (actually,
MS Office in general) add-ins that contain code to hook the auto macros. I
usually get around this by creating additional toolbars inside my own add-in
to load when the user starts Word. I used to create additional menu items,
but the latest version of Adobe Acrobat has completely taken over the main
menu.
 
T

Tony Jollans

I don't think that this has to do with the DMS particularly; it is to do
with how Word is started.

AutoExecs in global templates run when the templates are loaded - normally
on Word startup. When Word is started via Automation, they are suppressed by
Word. Although it's possible for the driving code to fire the autoexec in a
global template it is not entirely straightforward and it is unusual.

I do agree with you that the challenge is to find another way to achieve
what the questioner wants.
 
Z

zkid

Okay, back to you. You're just going to have to trust me on this one. The
document management program has hijacked the autoexec subroutine, and most
likely has also created hooks for the save, open, etc. operations.

To verify this, generally the DM programs have an unprotected global
template. Just go to the Word or Office startup directory, and retrieve
their template. Now, search for autoexec (do a full project search in case
there are multiple modules). All they have to do is create a sub called
autoexec, and that prevents you from doing the same.

The bottom line is that you will need to figure out another way to
accomplish what you need. It is unclear to me why you wish to change the
numpad period to a comma (if that is indeed what you're attempting to do),
but you do not have autoexec at your disposal to do so.
 
M

mmalinsky

Gentlemen,

What I'm trying to ultimately accomplish is to have the numpad key
reassigned to a comma. I spend enough time typing numbers (rounded to
the nearest dollar) into Word to see efficiencies in having this key
reassignment. I have the reassignment part worked out, as can be seen
from the code. The code is saved in an add-in file in C:\Documents
and Settings\Administrator\Application Data\Microsoft\Word\STARTUP,
not in Normal.dot.

I created a toolbar that is attached to the add-in file. The toolbar
has a button that is supposed to turn the reassignment on and off. I
would like the button to have a state of msoButtonDown when this
feature is turned on and msoButtonUp when turned off. I further
wanted to have the keybinding clear itself upon closing or opening
Word (doesn't matter which) so that I would always start Word with
msoButtonUp and the numpad decimal as a decimal. This was to be a
visual cue to me so I would have to guess. As I stated, this works
fine outside of the paperless software we are using, but apparently
the add-in installed wit the paperless software kills the ability of
auto macros to fire. When Word files are accessed then closed from
within the paperless software, Word apparently remembers the last
value of the keybinding so if the numpad decimal was assigned to a
comma when the last Word document was closed, the numpad decimal is
still assigned to a comma when another Word document is opened.

Sorry for this being more than a couple of sentences, but I wanted to
make sure you knew all aspects. :)

Thanks for the help.
Mike.
 

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