Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-05-2020, 09:02 AM
eduzs eduzs is offline Document before save macro? Windows 10 Document before save macro? Office 2019
Expert
Document before save macro?
 
Join Date: May 2017
Posts: 260
eduzs is on a distinguished road
Default Document before save macro?


Is there possible to create a document before save macro in normal dot file?
I mean a "document before safe" macro that works with any document, no need to be in each "ThisDocument" code.
Thanks
Reply With Quote
  #2  
Old 08-06-2020, 08:21 AM
gmaxey gmaxey is offline Document before save macro? Windows 10 Document before save macro? Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,422
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

You could set up a Application Event Monitor as a class in your Normal Template.


Add a new class module. Call it csAppMonitor and paste in the following code:
:
Code:
Option Explicit
Public WithEvents oAddInMontiorApp As Word.Application

Private Sub Class_Initialize()
  Set oAddInMontiorApp = Word.Application
End Sub

Private Sub oAddInMontiorApp_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
  MsgBox "Beep"
End Sub

In a standard module of your Normal.dtom, Declare:
Public oMonitor As clsAppMonitor



Then in the AutoExec sub
Set oMonitor = New clsAppMonitor
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 08-06-2020, 08:33 AM
eduzs eduzs is offline Document before save macro? Windows 10 Document before save macro? Office 2019
Expert
Document before save macro?
 
Join Date: May 2017
Posts: 260
eduzs is on a distinguished road
Default

Works fine!
Only modified the class module to clsAppMonitor.
Thanks!!!

Last edited by eduzs; 08-06-2020 at 01:25 PM.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Document before save macro? Macro to save Word 2007 document using info from Quick Parts staicumihai Word VBA 2 08-08-2018 01:21 AM
Cant save document as docx or doc using macro in Word 2007 staicumihai Word VBA 1 04-27-2018 10:59 AM
Document before save macro? Tweak Macro to Save Each Page of Word Document as Separate PDF or Doc File? Hewg74 Word VBA 3 08-22-2016 05:20 PM
Save As Macro using first line of document as document name redzan Word VBA 1 01-31-2015 09:24 PM
Document before save macro? How to save a macro in a document generated with a word model? Cristin7 Word VBA 4 03-25-2014 03:25 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:45 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft