Consulting

Results 1 to 4 of 4

Thread: Can't remove prompt asking to save changes

  1. #1
    Banned VBAX Regular
    Joined
    Aug 2010
    Posts
    54
    Location

    Can't remove prompt asking to save changes

    I'm using this to generate an email from Word;

    Sub EmailReturn()
        Dim OutApp As Object
        Dim OutMail As Object
        Set Doc = ActiveDocument
        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
    
        On Error Resume Next
        With OutMail
            .Subject = "Advice Return"
            .To = "Reviews Mailbox"
            .CC = ""
            .Importance = 2  'Importance Level  0=Low,1=Normal,2=High
            .Body = "Please find attached a Return for your information." & vbCrLf _
            & vbCrLf & "Please save this file to a suitable folder before opening to ensure full functionality."
            .Attachments.Add Doc.FullName
            'You can add other files also like this
            '.Attachments.Add ("C:\test.txt")
            .Display   'or use .Display
        End With
        On Error GoTo 0
        Set OutMail = Nothing
        Set OutApp = Nothing
    End Sub
    Once the email is generated then the following is run;

    Application.Quit SaveChanges:=wdSaveChanges
    What should happen is that the email is generated and the document itself closed in the background, leaving the user to check the email and send if they wish.

    The issue I'm having is that once the email is generated I get a prompt asking if I want to save changes with 3 options, YES, NO or CANCEL.

    If I click CANCEL then the prompt disappears leaving both the email and the document open. If I click NO then it closes the email but not the document, if I click YES then it gives me a message saying there have been changes made to the global template, (or something like that at least!).

    I should point out the following which may assist in finding a solution;

    I have created the document using Word 2007 on a Windows 7 PC - it works perfectly as expected in that scenario, however, when I deploy it to a work PC which is Office 2003 on Windows XP, that's when I get these issues.

    Could it be something like Outlook using Word as it's editor? If so I'd like to know if there is a workaround because I won't be able to account if the end user has that enabled or not.

  2. #2
    VBAX Regular arangogs's Avatar
    Joined
    Jun 2009
    Location
    Ayrshire, Scotland
    Posts
    18
    Location
    Hi Sharky,

    you could try the following:-

    ActiveDocument.SaveAs (ActiveDocument.Path)
    Application.Quit

    this will work, unless you are opening the word document from the code, as it will have no location. otherwise, job done.

  3. #3
    The code should work in 2003, regardless of whether Outlook 2003 is configured to use its own editor or Word. You can test for that, but it is not necessary unless you want to use the Word Inspector to edit the message body. It is the other code related to the process that is at issue and you have not listed that. In this instance I would simply add the document handling code into the macro, e.g.

    Sub EmailReturn()
    Dim wrdApp As Word.Application
    Dim OutApp As Object
    Dim OutMail As Object
    Dim Doc As Document
    Dim wState As Long
        On Error Resume Next
        Set wrdApp = Word.Application
        If wrdApp.Documents.Count = 0 Then
            MsgBox "No document open?"
            GoTo lbl_exit
        End If
        Set Doc = wrdApp.ActiveDocument
        wState = wrdApp.WindowState
        wrdApp.WindowState = wdWindowStateMinimize
        Doc.Save
        If Len(Doc.Path) = 0 Then
            MsgBox "The document must be saved first"
            GoTo lbl_exit
        End If
        Set OutApp = GetObject(, "Outlook.Application")
        If OutApp Is Nothing Then Set OutApp = CreateObject("Outlook.Application")
        If OutApp Is Nothing Then
            MsgBox "Outlook not available"
            GoTo lbl_exit
        End If
        On Error GoTo 0
        Set OutMail = OutApp.CreateItem(0)
        With OutMail
            .Subject = "Advice Return"
            .To = "someone@somewhere.com"
            .CC = ""
            .Importance = 2        'Importance Level  0=Low,1=Normal,2=High
            .Body = "Please find attached a Return for your information." & vbCrLf _
                    & vbCrLf & "Please save this file to a suitable folder before " & _
                    "opening to ensure full functionality."
            .Attachments.Add Doc.FullName
            .Display
        End With
        Doc.Close SaveChanges = False
    lbl_exit:
        Set OutMail = Nothing
        Set OutApp = Nothing
        Set Doc = Nothing
        Set wrdApp = Nothing
        Exit Sub
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  4. #4
    Banned VBAX Regular
    Joined
    Aug 2010
    Posts
    54
    Location
    Graham - that's really helpful, thank you - just for the record I tried the suggestion posted by arangogs but that didn't work - thanks to both though.

Posting Permissions

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