Consulting

Results 1 to 4 of 4

Thread: File SaveAs executing twice

  1. #1

    File SaveAs executing twice

    *** Sorry just noticed the typo in the title. Should say: "twice", not "twicen". (No drink taken).

    Hi All,

    Happy New Year. (At least it is New Year in Scotland).

    I normally make a nuisance of myself in the Excel forum, but tonight it's the Word forum's turn to be unlucky.

    I know very little about Word, so my question may well be entirely stupid, but here goes.

    I am using Office 2010, 32-bit on a stand-alone laptop.

    I have the following code in my document:

    ' This procedure sets the file extension as "docx" before save prompt
    
    
    Private Sub App_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
    With Application.Dialogs(wdDialogFileSaveAs)
         .Format = wdFormatXMLDocument
         .Show
     End With
    
    
    End Sub
    The active document at this point is a "docm" file as I have some VBA code in it. However, when the user saves the document I want it to save as a "docx" file. Therefore, I am trying to set the extension to save the user doing it. (All the Application code is already in place). The "docx" extension does show in the dialog box and the document saves as a "docx" file, without the VBA from the original file. However, the dialog box shows a second time, with a "docm" file type specified (as per the original file, which is still open). My question is how do I stop the dialog box showing a second time? Or, is there a better way of doing what I am trying to do?

    Many thanks and best regards.
    Last edited by El_Diabolo; 12-31-2013 at 06:35 PM. Reason: Typo in title

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Since you're calling the SaveAs dialogue within the before_save event, you'll get two save prompts for an unsaved document. is there a reason for not using 'SaveAsUI = True' to call the SaveAs dialogue? See the 'Application.DocumentBeforeSave Event' in Word's VBA help file.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Hi Paul and thank you for your reply.

    I looked at your suggested solution, but I don't understand how it works.i.e. why/how does setting the SaveAsUI = True call the SaveAs dialogue? Also, if using this approach how can I set the document type so that the user doesn't have to do it? If you could provide a code example that would be perfect, please. Many thanks.

  4. #4
    I managed to solve it. All that was required was to insert "Cancel = True" after the "End With" in the code I posted in post #1. I guess that makes me a VBAX master.

Posting Permissions

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