• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3886
  • Last Modified:

OnSave Event in VBA?

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
luckie
Asked:
luckie
  • 9
  • 6
  • 4
  • +1
1 Solution
 
bruintjeCommented:
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
 
luckieAuthor Commented:
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
 
bruintjeCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
luckieAuthor Commented:
Hi Brunintje,
    So Does this mean there would be no other ways to manufacture a save event in WORD VBA? :)
Thanks
Jacky
0
 
bruintjeCommented:
Hi Jacky ,
this is the closest you can get one i guess
Brian
0
 
starlCommented:
what version of word do you have? starting in 2000, there's a "DocumentBeforeSave" available.
0
 
bruintjeCommented:
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
 
luckieAuthor Commented:
WORD 97, but I'm planning to use WORD 2000.
0
 
starlCommented:
planning???? so, can the code wait till you get to 2000?
0
 
luckieAuthor Commented:
cos I use WORD97 at home, but I need to use WORD 2000 in the workplace. :)
Thanks
Jacky
0
 
blakeh1Commented:
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
 
blakeh1Commented:
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
 
luckieAuthor Commented:
Hi blakeh1,
    How do you 'connect' the SaveAs action to the macro specifically? Still, when there is no onSave event?

 
0
 
luckieAuthor Commented:
Or 'connect' the saveas Macro to the saveas menu
file->saveas...
or something like that?
0
 
starlCommented:
hmmm - you could rebuild the menu...is this for a certain document template? all uses?
0
 
blakeh1Commented:
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
 
luckieAuthor Commented:
give me a day or two... because too busy... come back ASAP
0
 
starlCommented:
blakeh - is this a 97 option??? I didn't see the "Word Commands" listing... (my 2000 is at home)
0
 
bruintjeCommented:
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
 
luckieAuthor Commented:
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
 
luckieAuthor Commented:
I think the points should to awarded to ... :)
0
 
bruintjeCommented:
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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

  • 9
  • 6
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now