How to catch a KeyPress event in word

G

Gina

Hi all.

I am trying to customize a word document so that a user is only allowed to
use custom buttons.
Anything else is hidden / disabled - that works alright ... apart from

1. how can I detect/ avoid a keyPress ( CTRL + S ) in order for the file
saveas dialog not to come up
when a word document is coming from template e.g. 'KD.dot' ?

2. how can I stop the user from possible disabling macros when
opening/closing my doc when template = KD.dot ?

3. do I have to think on anything else re my problem ?

any help highly appreciated - like always

thanks in advance

Gina
 
J

Jonathan West

Hi Gina,

Are you trying to prevent people from accidentally doing the wrong thing, or
are you trying to secure the document against unauthorised deliberate
modifications?

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
J

Jezebel

Gina said:
Hi all.

I am trying to customize a word document so that a user is only allowed to
use custom buttons.
Anything else is hidden / disabled - that works alright ... apart from

1. how can I detect/ avoid a keyPress ( CTRL + S ) in order for the file
saveas dialog not to come up
when a word document is coming from template e.g. 'KD.dot' ?

Assign that keystroke combination to your own macro.

2. how can I stop the user from possible disabling macros when
opening/closing my doc when template = KD.dot ?

You can't.
3. do I have to think on anything else re my problem ?

Depends on what your problem is, but I suggest you consider the implications
for the user of having Word behave in such strange and unpredictable ways.
If you're trying for security, it won't work. If you're trying to be
'helpful' your efforts are likely to be counterproductive: people *learn* to
use Word and expect it to behave in predictable, standard ways. Making
changes as you describe will annoy experienced users and confuse novices.
 
J

Jean-Guy Marcil

Gina was telling us:
Gina nous racontait que :
Hi all.

I am trying to customize a word document so that a user is only
allowed to use custom buttons.
Anything else is hidden / disabled - that works alright ... apart from

1. how can I detect/ avoid a keyPress ( CTRL + S ) in order for the
file saveas dialog not to come up
when a word document is coming from template e.g. 'KD.dot' ?

In your template, insert two subs as follows:

Sub FileSave()

End Sub

Sub FileSaveAs()

End Sub

These will make the save and save as actions "inert".
2. how can I stop the user from possible disabling macros when
opening/closing my doc when template = KD.dot ?

In short, you can't.
3. do I have to think on anything else re my problem ?


Maybe, it is difficult to comment as we do not really know why you want to
do these things...


Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
G

Gina

Hi Jonathan.

thanks for your answer .... I think the latter of your answer applies.

what I am trying to do:

in a document (new) generated by access and filled with data only two things
are allowed for the user apart from looking at it ;-))
print it, close it and quit word application itself without giving the
possibility of saving it

1. as single printout
2. as double printout
so this all works ... but keys like CTRL + S are still available

I know it sounds strange but I decided it is the right thing - all
customisation should be avoided
and I try to think of all possibilities.

Gina

..
 
G

Gina

Hi Jezebel.

To hide everything apart from my custom commandbar (with 2 buttons) is/was
in fact first to not confuse the novices ( I know, these people are bloody
novices!!! - they were still using a typing machine)
Second ... in order to avoid not renewing the license for my program but
make use of the template that comes with my access.mdb ( and all the work
that went with it) the document should not be allowed to save ...

it can always be generated by the access program

so I catered for that so far (thanks to the help of the group!!) and all
works fine more or less
all but the keypress thing and things I haven't thought of yet or do not
know

Gina
 
G

Gina

Hi Jean-Guy,

many thanks for code!!
will I have to leave these two subs blank ???

For what I am trying to do please see above answers to posts

Thanks,
Gina
 
J

Jonathan West

Hi Gina,

If you are trying to devise a security scheme for Word such that documents
can't be edited, let me tell you that nothing you can do within Word will
prevent a sufficiently determined and resourceful user from breaking the
security. For instance

1. Opening the document with Word set to High or Very High security will
prevent all VBA code from running.

2. Inserting the document into a blank document will strip off all VBA code.

I can think of several other ways of breaking the security.

I'm just trying to warn you off spending a lot of time and effort pursuing
an unattainable technical solution to this.

If a technical solution is not possible, then you have to consider other
approaches - and this essentially consists of educating your users to behave
right. Then you don't *need* all this security.

If you really want a document that can just be viewed and printed, then I
suggest you buy a copy of Adobe Acrobat and convert it to PDF format and
apply the appropriate security to the PDF file.

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
G

Gina

Jonathan...

oh ... oh ... dear ....
well .... nothing really I can do, can I....
NOPE

I am more or less happy with what I got right now - nothing more is
posssible
I got rid of the ctrl + s keypress by using Jean-Guy's code

ok ... so at this point I can stop spending more time on my strange idea
:-((

despite all ... thanks for your answer !!

have a nice weekend
Gina
 
J

Jean-Guy Marcil

Gina was telling us:
Gina nous racontait que :
Hi Jean-Guy,

many thanks for code!!
will I have to leave these two subs blank ???

For what I am trying to do please see above answers to posts

If you leave them blank, nothing will happen, or, you could warn the user
with:

MsgBox "You are not allowed to save a copy of this document."

Whatever code you put in the subs will be executed whenever the user tries
to save (or save as).

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
K

Klaus Linke

.... but even without knowledge (or acess) to VBA, users could still choose
"Tools > Macro > Macros in: Word Commands > SaveAs" (if they kow about it)
to run the built-in command.

Klaus
 
J

Jean-Guy Marcil

Klaus Linke was telling us:
Klaus Linke nous racontait que :
... but even without knowledge (or acess) to VBA, users could still
choose "Tools > Macro > Macros in: Word Commands > SaveAs" (if they
kow about it) to run the built-in command.

....or disable macros all together...

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
G

Gina

Klaus ....

thanks for reality ;-)
well.... in the doc generated by access and opened with a macro in word that
disables all but a custom bar that contains two buttons (to print it), they
of course have the option of editing it in some way as well as copy and
paste ( via keyboard) presumably text from the clipboard ....

I tested to set the security settings to high as suggested earlier in this
thread .... and was really disarming :-((
absolutely no macro runs ....

so if the settings are not at the highest level, or the one below I cannot
see how they could choose
"Tools > Macro > Macros in: Word Commands > SaveAs" (if they kow about it)

because there is no menu either .... being very doubtfull about my basic
word knowledge !!
I wonder how then what you suggested could happen .... ??

Gina
 
K

Klaus Linke

Hi Gina,
because there is no menu either [...]

Yeah, missed the point that you customized that away. The user would have to
add it again?
Say with "right-click > Customize" on your toolbar...

My point, same as all others that responded, is that you likely can't close
all the loopholes.

Regards,
Klaus
 
G

Gina

No Klaus ... there is no right-click either anymore .....
I very much appreciate all your answers and ideas I have not thought of
..... ( believe me, it took some time as well as big help from the group!!
before I got word where it is now and normal.dot and any other word stuff
still behaving 'normal' .... when the security settings are not high ....
only my templates are affected of all that disabling customisation stuff!!

as they are novices anyway .... they won't know about at least not in the
nearer future :) .... I hope :))
all the data transfer to word, proper formatting etc ... etc... took quite
an amount of programming in access together with preparing the templates
with company logos etc. to give it 'em the same look as the ones from the
typing machine ( they just look - of course - more neet and accurate) ...

I just wanted to make sure that I have done my best .... with the given
elements....
I will see ;-))

Thanks to everyone who answered this and my other threads in the word group
adding to my 90% success in this case - that got more and more suprises for
me to solve as I went along !!

Just one thing comes to my mind .... if the user wouldn't know that it is
Word what is showing up the document, a normal user would not know to change
security settings to high in order to not run any of the underlying vba so
that a 'save' could be performed
oh dear .... this gets a mad touch now ....
is it possible to remove the first 'bar' where it becomes clear which
program is opened ??? showing Dokument 1 - Microsoft Word .... well I would
have to get rid of the icon in the top left corner as well ....

I guess or I am sure microsoft wouldn't allow for that!!

Gina


Klaus Linke said:
Hi Gina,
because there is no menu either [...]

Yeah, missed the point that you customized that away. The user would have to
add it again?
Say with "right-click > Customize" on your toolbar...

My point, same as all others that responded, is that you likely can't close
all the loopholes.

Regards,
Klaus


Gina said:
Klaus ....

thanks for reality ;-)
well.... in the doc generated by access and opened with a macro in word
that
disables all but a custom bar that contains two buttons (to print it),
they
of course have the option of editing it in some way as well as copy and
paste ( via keyboard) presumably text from the clipboard ....

I tested to set the security settings to high as suggested earlier in this
thread .... and was really disarming :-((
absolutely no macro runs ....

so if the settings are not at the highest level, or the one below I cannot
see how they could choose

because there is no menu either .... being very doubtfull about my basic
word knowledge !!
I wonder how then what you suggested could happen .... ??

Gina
 

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