Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

OnSave Event in VBA?

Posted on 2002-04-24
22
Medium Priority
?
3,857 Views
Last Modified: 2007-11-27
There are only new, open and close events in a WORD document with VBA. Where are OnSave, Onalign events? How do I make a procedure for these?
Thanks

0
Comment
Question by:luckie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 6
  • 4
  • +1
22 Comments
 
LVL 44

Expert Comment

by:bruintje
ID: 6967816
Hi Luckie,

Check the object model inspector

-open Word
-goto the VB Editor with ALT+F11
-then use F2 to birng it up
-now look for all events | properties you need info about

for save it's the ActiveDocument.Save you need to call the method, there's no event triggered except for close

about the align which align, from a picture or a page or something?

maybe if you could explain what you're trying to do we can come with an more precise suggestion

HTH:O)Bruintje
0
 

Author Comment

by:luckie
ID: 6968075
I'm trying to for example, open up a messagebox when the user clicks on the Save/Save As... button.
So what you mean is to code under the close event for this situation? (by putting ActiveDocument.Save under Document.Close)? Hope I get across the concept right..
Thanks
Jacky
0
 
LVL 44

Expert Comment

by:bruintje
ID: 6968101
Hi Jacky,

-what you can do is a bit of a workaround
-make your own save procedure

it works like this
--> first build your own save script

public sub MySave
  'do something here
end sub

-->now place this code into your template (could be normal.dot or whatever)
-->then close the VB Editor
-->then in Word
-->choose tools | customize
-->choose the first tab
-->in the list look for macros
-->click and in the right pane there will be MySave
-->drag this one to the file menu
-->place it under the Save or something
-->give it a decent menu name like Save Special or something

-->you can also add the macro to the exisitng Save menu if that's more convenient

HTH:O)Bruintje
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:luckie
ID: 6968320
Hi Brunintje,
    So Does this mean there would be no other ways to manufacture a save event in WORD VBA? :)
Thanks
Jacky
0
 
LVL 44

Expert Comment

by:bruintje
ID: 6968343
Hi Jacky ,
this is the closest you can get one i guess
Brian
0
 
LVL 8

Expert Comment

by:starl
ID: 6970309
what version of word do you have? starting in 2000, there's a "DocumentBeforeSave" available.
0
 
LVL 44

Expert Comment

by:bruintje
ID: 6970329
ok, it's an application level event so you've got to catch it for it all open documents, if you decide to use it then you should check for the current document

thought it was meant to go from the current document and to perform a special action, but it's an alternative nonetheless

btw what's the purpose, you've to perform any special action on the save event?

:O)Bruintje
0
 

Author Comment

by:luckie
ID: 6970415
WORD 97, but I'm planning to use WORD 2000.
0
 
LVL 8

Expert Comment

by:starl
ID: 6971142
planning???? so, can the code wait till you get to 2000?
0
 

Author Comment

by:luckie
ID: 6971713
cos I use WORD97 at home, but I need to use WORD 2000 in the workplace. :)
Thanks
Jacky
0
 
LVL 6

Expert Comment

by:blakeh1
ID: 6972242
You can have macros you create triggered when a certain action is run, if you Name a macro FileSaveAs this will get triggered when someone hits File, Save As, the problem with this is that you now have to code in your own save as macro (this will NOT get triggered if someone uses File, Save, or hits the Save button on the toolbar and the document has never been saved). For File, Save you will have to repeat the same thing. You will need to create error handling in the case they hit cancel in the save as dialog.

Sub FileSaveAs()
    Dim dlg As Dialog
    Dim sFileName As String
    MsgBox "Trapping and replacing the FileSaveAs command"
   
    Set dlg = Application.Dialogs(wdDialogFileSaveAs)
    dlg.Display
    dlg.Execute
   
End Sub

Sub FileSave()
    MsgBox "Trapping and replacing the FileSaveAs command"
    ActiveDocument.Save
   
End Sub
0
 
LVL 6

Expert Comment

by:blakeh1
ID: 6972248
Of course those macros will have to be created in the normal.dot file, and anyone you expect to be using this will either need to have to share a single normal.dot, or will need a copy to replace there exisiting normal.dot.
0
 

Author Comment

by:luckie
ID: 6972954
Hi blakeh1,
    How do you 'connect' the SaveAs action to the macro specifically? Still, when there is no onSave event?

 
0
 

Author Comment

by:luckie
ID: 6972955
Or 'connect' the saveas Macro to the saveas menu
file->saveas...
or something like that?
0
 
LVL 8

Expert Comment

by:starl
ID: 6973220
hmmm - you could rebuild the menu...is this for a certain document template? all uses?
0
 
LVL 6

Accepted Solution

by:
blakeh1 earned 200 total points
ID: 6977359
By creating a macro in your Normal.dot that is called FileSaveAs, word will trigger that macro whenever someone uses File, Save As. Likewise creating a macro called FileSave will be triggered when someone uses file, save  (or clicks on the toolbar button). By naming macros the same as the built in Word commands these intercept them (which means you will have to write your own routine something like the sample above. To see the list of word commands go to Tools, Macros, and the dropdown for Macros In, choose Word Commands.
0
 

Author Comment

by:luckie
ID: 6977383
give me a day or two... because too busy... come back ASAP
0
 
LVL 8

Expert Comment

by:starl
ID: 6980671
blakeh - is this a 97 option??? I didn't see the "Word Commands" listing... (my 2000 is at home)
0
 
LVL 44

Expert Comment

by:bruintje
ID: 6982911
Well there are some relevant suggestions in this thread why not wrap it up?

-changing the menu is a common theme
-adding a custom save item or replacing the current save seems to be the open question

did you find anything usefull in these proposed solutions or are you still looking to replace the event, which isn't an option and the suggestion from blakeh1 comes closest to this

:O)Bruintje
0
 

Author Comment

by:luckie
ID: 6983105
OK... let's finish it off. But Can I split the points between bruintje and blakeh1? Both of you gave me a lot of useful information... :)
0
 

Author Comment

by:luckie
ID: 6983114
I think the points should to awarded to ... :)
0
 
LVL 44

Expert Comment

by:bruintje
ID: 6983576
forget about point splits, since the stupid minimum rule it's not smart to split points only if they are more then 100 it would be doable, i like it this way i got the PAQ anyway and two ways to solve this problem :)
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
Ever wonder what it's like to get hit by ransomware? "Tom" gives you all the dirty details first-hand – and conveys the hard lessons his company learned in the aftermath.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question