Trouble with Application.GetSaveAsFilename RRS feed

  • Question

  • I'm using VBA in Word 2010 to automate the population of project details (job #, client details, etc.) into a master report template.  I've got the most important parts working just fine (albeit SLOW!), but would like for the user to be prompted to save modified document into a different folder (so that the master file isn't overwritten every time) before the substitutions are made  This isn't my first program (having started with FORTRAN in 1977 or so) nor my first foray into VBA.  But the file manipulation has me thoroughly befuddled.

    Here's the code in question (it isn't complete yet - with unrelated code snipped out for brevity):

    Sub myReplaceText()

        Dim NewText(29), IntialName, saveAsName As String
        Dim fileSaveName, myDialogBoxTitle As Variant

    'SNIP lots of code

    'NewText values are pulled from an Excel spreadsheet in other code

        NewText(2)="Grand Hyatt Hotel"
        InitialName = NewText(1) & " " & NewText(2) & " Final Report"
        saveAsName = InitialName & ".docx"
        myDialogBoxTitle = "Where do you want to save the file?"
    'The following statement is my problem
        fileSaveName = Application.GetSaveAsFilename(saveAsName, "*.doc*", myDialogBoxTitle)

        If fileSaveName <> False Then
            MsgBox "Save as " & fileSaveName
        End If

    End Sub

    I'm getting an error before any of the code executes:

    Compile error:
    Method or data member not found

    And Application.GetSaveAsFilename is highlighted.  I'm baffled.  I have the following references selected/activated:

    Visual Basic for Applications
    Microsoft Word 15.0 Object Library
    OLE Automation
    Microsoft Office 15.0 Object Library
    Excel PlugInShell 1.0 Type Library
    Microsoft Excel 15.0 Object Library
    Microsoft DAO 3.6 Object Library
    Microsoft ADO Ext. 6.0 for DDL and Security

    What am I missing?

    Tuesday, January 6, 2015 10:09 PM

All replies

  • <sigh>

    The answer is actually very simple: there is no  Application.GetSaveAsFilename in Word's VBA.  Go figure.  The following code works:



    'Now save the Word file to a new name and location BEFORE it is changed

        Dim IntialName, saveAsName, mySaveAsFilePath As String
        Dim fileSaveName, myDialogBoxTitle As Variant
        Dim dlgSaveAs As FileDialog

        InitialName = NewText(1) & " " & NewText(2) & " Final Report"
        saveAsName = InitialName & ".docx"
        mySaveAsFilePath = "G:\Projects\"

    Set dlgSaveAs = Application.FileDialog(FileDialogType:=msoFileDialogSaveAs)

    With Dialogs(wdDialogFileSaveAs)
        .name = mySaveAsFilePath & saveAsName
    End With

    ' perform the replacements


    My code is now working; hope this helps someone else.

    Wednesday, January 7, 2015 8:27 PM