Consulting

Results 1 to 3 of 3

Thread: Using VBA to display dialog box when saving files in Office 2007

  1. #1
    VBAX Newbie
    Joined
    Jul 2008
    Posts
    1
    Location

    Using VBA to display dialog box when saving files in Office 2007

    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.

  2. #2
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    Just so you know, you can set the default save type in word (read this):
    http://office.microsoft.com/en-us/wo...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:
    [vba]Option Explicit

    Public g_AppEvents As ApplicationEvents[/vba] 3.) Create a Class Module called "ApplicationEvents"
    4.) Place this code in it:
    [vba]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[/vba] 5.) In the ThisDocument module (still in Normal.Dot) place this code:
    [vba]Option Explicit

    Private Sub Document_Open()
    Set g_AppEvents = New ApplicationEvents
    End Sub[/vba]
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  3. #3
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •