PDA

View Full Version : CONTROLLING DOCUMENT SAVE



timetunnel
02-14-2007, 11:00 AM
Greetings to all:

Does anyone know if it's possible (and if it is, how to) disable the FILE/SAVE function within word?

I'm running a little VBA menu system with options to 1) open 2 documents, 2) save the 2 documents after they're updated, 3) merge the 2 into a new document and )4 save the new document.

What I want to do is to prevent the users from clicking on FILE/SAVE and defeating the menu system, because I want to control the naming conventions and where the documents are saved, which I do with the menu options.

I've tried hacking some code together, but I'm not very skilled and haven't gotten anywhere.

Any help is greatly appreciated.

By the way, thanks to everyone here who helped my with my previous questions. Thanks to all of you I was able to hack together the menu system mentioned above and it's really starting to come together.

Regards

MAN IT BYTES GETTING OLE...

Marcster
02-14-2007, 11:32 AM
Does anyone know if it's possible (and if it is, how to) disable the FILE/SAVE function within word?


Just type the following in the ThisDocument module:


Sub FileSave()
MsgBox "File Save disallowed."
End Sub


You can overide all the other commands in the same manner.
So for example to overide the file > new

Sub FileNew()
Msgbox "File New disallowed."
End Sub


For the full list of Sub names you can overide:
Tools > Macro>
Macros in box
Word commands

HTH

Marcster.

timetunnel
02-15-2007, 09:42 AM
Thanks Marcster
However, I'm not sure this is going to work for me and it doesn't seem to be doing anything as I can still do File/Save.

I've hacked together this little VBA "menu" to control managing several documents that users work with daily.

The template with my menu system is sort of the "control module" and just sits there waiting on options to be taken.

When the user takes the option to open up a 2 document "set", I want to have save disabled so users are forced to take another option from my "control module menu" when it's time to save the 2 docs. That save option saves the 2 docs "behind the scenes" so the user can't change the names of the docs and also can't mess with the path.

This all works perfectly, but the problem is that the non-compliant "adventurous" user can still do File/Save and mess this whole system up.

So my ultimate objective is to disable File/Save and force the save operation to be executed with my VBA code via a menu option button.

I hope I haven't made this explanation too unwieldy!

Regards...

It bytes getting ole...

fumei
02-15-2007, 10:22 AM
Did you you actually write in a Sub FileSave() procedure? It will, for sure, work to trap File > Save, Ctrl-S, AND the Save button.
Sub FileSave()
Msgbox "Yadda yadda"
End Subwill not trap FileSaveAs. To do that you need to also write in a Sub FileSaveAs() procedure.

Are you saying that you have put in a Sub FileSave - like Marcaster's suggestion - Sub FileSave()
MsgBox "File Save disallowed."
End Suband you do NOT get that message...and nothing else? That you CAN do a File > Save? Because you sure should not be.

timetunnel
02-16-2007, 09:54 AM
Thanks Fumei (& Marcster):
After messing around with it a bit, it does in fact work as described. However, what threw me is that the code had to be placed in the "This Document" in my "control module - menu" template and in all of the other templates that are opened via the menu template in order for it to work.

I tried other combinations and if this configuration was altered it wouldn't work. Seems sort of strange, but I'm cool with it. I am running Word 97, so maybe it responds differently. Now at work where this will be used the version of Word is much newer!

Anyway, I really appreciate this info. I looked at some other possible ways to get at this and they were overly complex and really inappropriate for this application. This is perfect!

Regards,

fumei
02-17-2007, 08:07 AM
Uh, Marcaster DID state for it to go into ThisDocument.

timetunnel
02-17-2007, 11:38 AM
I get that Fumei. My confusion is why it had to go into the This Document in the "menu" template, when the saves in question were other templates opened by the menu template.

Anywho, it works just dandy in my work environment and I appreciate all the help!

Regards,

TonyJollans
02-17-2007, 12:53 PM
I can't check to confirm on Word 97 at the moment (I am on a computer with Word 95!) but FileSave and other intercept macros do not have to go in the ThisDocument module and I'm pretty sure that's the case in Word 97 as well. They must go somewhere that is 'in scope' for the document you're trying to save - and that is the document itself, its attached template (or any other referenced template) or any global template (including Normal) and they can go in ThisDocument or any normal module in any of these places.

If you really are opening (or saving) templates as opposed to documents then the routine will have to be in some global (or referenced) template, but still should work in a normal module. When you mention the 'control module' and 'menu template' I'm not quite sure what you're referring to, I'm afraid.

timetunnel
02-17-2007, 05:00 PM
Hi Tony:
Just to clarify, My references to "Menu and Control Module" refer to a template that when opened, displays a VBA menu with option buttons and command buttons and serves as the control point of a report management system.

The purpose of this is to control the opening of templates, updating, saving, merging those templates into a new document and saving the new document in a predetermined location.

I need this level of control to prevent the users from running hog-wild with the use of the templates and the creation of the new document.

Hopefully I'm pretty much there with everything - for now...

Regards,

fumei
02-17-2007, 10:32 PM
Tony is asking because template files themselves should not be opened - or not when being used. You keep mentioning opening the template. In production use, templates are never opened, they are used to clone new documents.

He is also correct (of course) that it does not have to be in ThisDocument. I only mentioned it because Marcaster did mention it, and you wrote:
the code had to be placed in the "This Document" in my "control module - menu" templateIt can be in any module that has scope.

timetunnel
02-18-2007, 02:37 PM
Where I got the ThisDocument insertion was:


Just type the following in the ThisDocument module:





VBA:
Sub FileSave() MsgBox "File Save disallowed." End Sub



Also, I don't understand VBA enough to comprehend the "scope" business.

I guess what needs to happen is that I should invest in a VBA for dummies book and start woodsheding. My problem is that I'm not a spring chicken and I'm so fried from going back to work (after retiring nearly 4 years ago), that I really don't have the motivation, not to mention the energy!

Once again, thanks to everyone...