Share via

How to set Path for wdDialogFileSaveAs Dialog?

Anonymous
2011-07-25T22:41:14+00:00

I am trying to use wdDialogFileSaveAs in a macro so my user can save their doc after they have filled it in.

Since the macro is in a template, when the dialog opens, it always opens in the default template folder and not where the doc should be saved.

I have used .Name after setting it to a concatenation of the FilePath & the FileName. That didn't work.

I have used ChangeFileOpenDirectory to set the folder and that doesn't work, either.

The really weird thing is that if I just try calling the SaveAs macro, it works, but if I call it from another macro, it fails every time.

Any help would be greatly appreciated.

TIA,

Bob Mathis

Code:

*********************************************************************

Option Explicit

Public Sub SaveAsMacro()

    Dim strPath                                             As String

    Dim strFile                                             As String

    strPath = "C:\Documents and Settings\isd109\Desktop"

    strFile = "_My Test.doc"

    ActiveDocument.SaveAs _

            FileName:=strPath & strFile, _

            FileFormat:=wdFormatDocument, _

            LockComments:=False, _

            Password:="", _

            AddToRecentFiles:=True, _

            WritePassword:="", _

            ReadOnlyRecommended:=False, _

            EmbedTrueTypeFonts:=False, _

            SaveNativePictureFormat:=False, _

            SaveFormsData:=False, _

            SaveAsAOCELetter:=False

End Sub

*********************************************************************

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

Anonymous
2011-07-27T14:36:33+00:00

I found the problem. I was always running the template by stepping through the code. When I ran it by just clicking on the template, everything works perfectly.

So, for whatever reason the IDE was preventing it from working. Probably like debug statements won't work in compiled VB code, but will in the IDE, only this is just the opposite.

Thanks for all your suggestions.

Bob M.

Was this answer helpful?

0 comments No comments

8 additional answers

Sort by: Most helpful
  1. Anonymous
    2011-07-26T14:53:42+00:00

    I don't have a solution for you (yet), but I have several more questions:

    • Is the code in your latest post the only code in the macro you're trying to run?
    • What is the value of ActiveDocument.Name when that macro starts? (Use the Watch window and run the macro by repeatedly pressing F8 to find out.)
    • When the error message appears, does it include an error number? If so, what it it?
    • Does the error occur when you run step-by-step with F8?
    • There are a total of 49 macros in the project.
    • ActiveDocument.Name = "_New NeoGov Wizard.dot" which is correct, but the folder is that template folder and not "C:\My Documents" (C:\My Documents" DOES exist.)
    • I get "Run - Time Error '4198'      Command Failed"  and it just stops without showing what line it is on. But I know it is in this macro because I do not get it if I comment out the macro call.
    • I do not get the error if I go step-by step. I do not get it if I Just click in that macro and hit F5.

    I only get the error when running the project as a whole.

    Thanks,

    Bob

    Was this answer helpful?

    0 comments No comments
  2. Jay Freedman 207.7K Reputation points Volunteer Moderator
    2011-07-26T14:27:11+00:00

    I don't have a solution for you (yet), but I have several more questions:

    • Is the code in your latest post the only code in the macro you're trying to run?
    • What is the value of ActiveDocument.Name when that macro starts? (Use the Watch window and run the macro by repeatedly pressing F8 to find out.)
    • When the error message appears, does it include an error number? If so, what it it?
    • Does the error occur when you run step-by-step with F8?

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2011-07-26T13:28:24+00:00

    I need to open the dialog in a preset folder with a preset file name. From there, the user can change the folder or file name if they wish, or just click the 'OK' button. 90% of the time, they will just click 'OK', but they do need the option of changing things if they need to.

    If I use:

    With Dialogs(wdDialogFileSaveAs)

        .Name = "C:\My Documents" & ActiveDocument.Name

        .Show

    End With

    I get a message "Command Failed" and it exits the Macros.

    Thanks,

    Bob M.

    Was this answer helpful?

    0 comments No comments
  4. Jay Freedman 207.7K Reputation points Volunteer Moderator
    2011-07-25T23:49:00+00:00

    Exactly what are you trying to achieve? Is it to save the document with a specified name in a specific folder without using the SaveAs dialog (which is what will happen with the code you posted)? Or is it to change the location that opens in the SaveAs dialog (which is what your post's title implied)?

    If you really want to affect the dialog, you need to use code like that in http://www.word.mvps.org/FAQs/MacrosVBA/ChangeSaveAsPath.htm.

    Was this answer helpful?

    0 comments No comments