Wrox Programmer Forums
|
Word VBA Discuss using VBA to program Word.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Word VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 6th, 2006, 10:44 AM
Registered User
 
Join Date: Sep 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default run code on save??

hello there, i have made some code to take details from the document and to put them into document properties which i want to run when the user saves the document.

i have searched high and low and cannot for the life of me work out how to run this on save.

any help is greatly appreciated, thanks.

 
Old September 8th, 2006, 12:29 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Probably your best bet is to provide the users with a button to save the document. Have this button run a macro of your own authorship.

Hard to force them to use your button, I know. But if you have the authority, maybe you could use the Document_Open event to remove the standard save entry on the File menu, as well as the save button on the Standard toolbar, and substitute your own menu entry and buttom, each of which look identical to the "stock" items.

It’s a lot of work, but it is doable...
 
Old September 29th, 2006, 05:32 AM
Authorized User
 
Join Date: Sep 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi there,

You'll need to install a macro in the user's Normal template, or in a Global Add-in to Word - depending on the user's setup (personally I use an Add-In in the user's start-up path - see Tools > Options > File Locations)

Any macro that has the same name as a Word command will override the Word command. You need macros named "Save", "Save As", and "Save All".

Write the macros with VBA and store them in a template. If you use the user's Normal template, you can have the macro save to different locations per user. But you need to be aware that users break their Normal.dot templates regularly, and when they do, your macro will go away.

Better to use an Add-In. An add-in is simply a template that has been installed as an Add-In. This template can be a single file for all users, mounted on the network. It can also be read-only (a Normal Template must never be read-only, and must never be shared).

To get the add-in installed you need to place your code within a templates (add-in) and install it to the user's Word start-up location (as I mentioned before). You can change this locaiton to be a network location which works fine, but I prefer to have a system where by the template is replciated to the user's local machine to avoid corruption or access of the master copy by unauthorised users.

You code will be some thing like:

Sub Save()
    'enter code here
End sub


Note that this code will override the actual word save command so you will need to add this into your custom code!

Hope this helps

Squarecat


 
Old December 29th, 2006, 04:28 AM
GLM GLM is offline
Authorized User
 
Join Date: Dec 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

little correction
the procs. names must be
FileSave, FileSaveAs ...

glm





Similar Threads
Thread Thread Starter Forum Replies Last Post
JSP Cannot save Modified Code Q4Java JSP Basics 3 September 15th, 2007 01:27 AM
Save file location code. JpaulH Access VBA 2 June 9th, 2006 07:50 AM
ACCESS 2000 VBA CODE TO "SAVE AS" EXCEL ckentebe Access 0 May 25th, 2004 02:13 PM
program code for "save" (F9) command mario_fluegge Access 3 August 8th, 2003 04:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.