PDA

View Full Version : Using VBA to display dialog box when saving files in Office 2007



LeonIRL
07-29-2008, 06:27 AM
Hi all,

I have been given the task of creating a message box which will appear whenever a user saves a file with any of the Office 2007 applications.

This dialog box will simply give the user a reminder to save it in the correct format (new Office 2007 format for internal company use, and older Office 2003 format for external use to ensure backward compatibility).

My question is; Is there a way to create a simple message box once the user has pressed Save -> Save as Word Document (the default format, regardless of what it is), with VBA?

Is VBA the route to go?

Regards,

Leon
H.J. Lyons & Co.

Oorang
08-07-2008, 06:50 AM
Just so you know, you can set the default save type in word (read this):
http://office.microsoft.com/en-us/word/HA102406831033.aspx?pid=CH101778931033

But if you want to do a code solution, in the users Normal.dot vba project you need to do the following.
1.) Create a Standard Module called "PublicObjects"
2.) Place this code in it:
Option Explicit

Public g_AppEvents As ApplicationEvents 3.) Create a Class Module called "ApplicationEvents"
4.) Place this code in it:
Option Explicit

Private WithEvents objWordApp As Word.Application

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

Private Sub Class_Terminate()
Set objWordApp = Nothing
End Sub

Private Sub objWordApp_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
If SaveAsUI Then
MsgBox "Don't forgot to save as rtf.", vbApplicationModal + vbMsgBoxSetForeground
End If
End Sub 5.) In the ThisDocument module (still in Normal.Dot) place this code:
Option Explicit

Private Sub Document_Open()
Set g_AppEvents = New ApplicationEvents
End Sub

Charlize
08-25-2008, 03:31 AM
Why not give the option to save it as an internal document. Adapt the messagebox with a yes/no question. Yes, save as internal document, No, save in 2003-format.

Charlize