Share via

why does fd = Application.FileDialog(msoFileDialogSaveAs) not save as .docm but as .docx?

Anonymous
2011-07-28T18:33:44+00:00

Hi Folks!

I use this this code to prompt the user to save, wiht a proposed filename, which must be a .docm so my macros continue to function:

        ProposedFilename = TextBox1.Text + "-ucs-" + TextBox2.Text + " " + TextBox3.Text + ".docm"

        Set fd = Application.FileDialog(msoFileDialogSaveAs)

        With fd

        .InitialFileName = ProposedFilename

        If .Show = 0 Then 'user pressed the cancel button

        Else

            .Execute

        End If

        End With

        Set fd = Nothing

        End If

        Unload Me

The file extention proposed in the prompt is .docx (while I defined it as .docm), why is this?

I did check the .InitialFilename, and the extention IS .doc, so why does Word change this?

Best wishes, Peter Hansen

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

HansV 462.6K Reputation points
2011-07-28T18:59:26+00:00
  1. You must set the FilterIndex to 2, because Macro-enabled documents are the second file type in the list.
  2. Execute doesn't actually save the document, you have to do that yourself. FileDialog only lets the user specify a path and filename.

    Set fd = Application.FileDialog(msoFileDialogSaveAs)

    With fd

        .FilterIndex = 2

        .InitialFileName = ProposedFileName

        If .Show Then

            ActiveDocument.SaveAs2 FileName:=.SelectedItems(1), _

                FileFormat:=wdFormatXMLDocumentMacroEnabled

        End If

    End With

    Set fd = Nothing

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2011-07-29T13:42:31+00:00

    Point 1) was the solution, but I do not agree with point 2). The document does get saved when I .execute.

    Anyway, I am happy. Thanks a lot. I am impressed, I am here for the first time, but already spread the message to my colleagues how well this site works.

    Was this answer helpful?

    0 comments No comments