Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Disable word's save toolbar button and file menu button
Message
De
16/03/2001 06:34:26
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
15/03/2001 13:09:26
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Divers
Thread ID:
00485474
Message ID:
00485767
Vues:
31
>Hi UTers'
>
>Is there a way to disable the SAVE button from the standard toolbar or the entire standard toolbar via automation? I also need to disable the FILE|SAVE menu selection from the system menu.
>
>You see, I don't want a user to save the modifications to a document he or she might have modified. I know that I could create a temporary copy of the document, allow the user to make changes to the copy, and at the end of the automation session simply delete the temporary file thereby not saving the changes. Yes, this will protect the original document from the user's changes but the user is receiving visual cues that he or she can save the document via the standard toolbar and the FILE|SAVE menu items. It is for that reason that I would prefer just to disable the saving options from the standard toolbar and FILE|MENU menu items.
>
>Thanx
>DR. G. (Neil)

Hi again Neil :)
This is a duplication for you I know. Others might benefit.

Neil,
It's surprisingly fairly easy to do that but it's also easy to hurt yourself
in addition.
First code that disables Save from Menu and Toolbar :
oWord = createobject("Word.Application")

lcFile = getfile('DOC')
if empty(lcfile)
 return
endif
with oWord
 .Documents.Open(lcFile)
 .Application.CommandBars("Standard").Controls("Save").Enabled = .F.
 .Application.CommandBars("File").Controls("Save").Enabled = .F.
 .visible = .t.
endwith
This doesn't prevent from 'Save Changes ?' dialog popup if modifications are
made when user tries to exit word or close doc. Simple workaround is to open
doc as readonly.
However changes to Save button and menu bar option causes it to be saved to
normal.dot and thus even if the user launches word at a later time
independent from VFP s/he will still have those 2 disabled. IOW if you
disable them via automation you're responsible to set them back to enabled
(checking word's existence with a timer probably).

Now for a moment think there is no problem in enabling-disabling them and
you did that way. Still same doc could be opened independently from VFP and
modifications saved or saved as. Right ? Normal prevention for that is to
password protect the file. There is 2 passwords you can set for a file
(open - modify). So I would recommend instead of disabling buttons :

-Open the doc as ReadOnly
-If you want to prevent modifications independent from VFP use
'WritePasswordDocument' - modify
-If you even want to prevent 'Save As' use 'PasswordDocument' - open
(However this wouldn't prevent it from SaveAs once opened from VFP via
automation - in that case you could disable-enable Save As and some
additional things explained below)

You could then open the doc as ReadOnly providing the password(s) from VFP
via automation (See documents.Open() syntax).

Now last challenger for paranoids:) is to disable any kind of save/saveas
for the doc. I don't think you want to that also but as info :

-You could create a VFPCOM.ComUtils object - say named oVFPCOM
-Using oVFPCOM.BindEvents you could control DocumentBeforeSave event
directly from VFP (However there is no guarantee that this would work with
Word versions prior to word2000)

Let's summarize :)
The simpliest approach is to save template doc with a Modify password if
also independent modification wouldn't be allowed (a clever user could
SaveAs, delete original and rename new but it's a matter of respect - you
can't prevent suicides:)

All you would do is to open doc as readonly :

oWord.Documents.Open(lcMydoc,,.T.) && Regarding to your post sounds this is
all you need

If you also have 'open' password set it in automation :

oWord.Documents.Open(lcMydoc,,.T.,,lcOpenPassword)

BTW readonly opening doesn't prevent modification in fact but prevents save
(I assume this is related with your previous myDoc.doc pasting so you can
still paste - and for that reason I didn't just say use a template).

Hope writing long I didn't make it confusing and helps:)

Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform