Set correct Drive and Folder when opening Application.Dialogue(xldialoguesaveas).show

kengooch

Member
Local time
Today, 06:20
Joined
Feb 29, 2012
Messages
137
So I often build a file name and then open the Application.Dialogue(xldialoguesaveas).show option to allow the user to make any changes to the file name that they need to make, however, I can't get the code to open the specified directory.
I found a snipit of code that is supposed to work for network drive locations but noted in the middle of the code down where the saveas dialogue shows, but it didn't seem to work either. And I did include the Private Declare Function SetCurrentDirectoryA Lib "kernel32" (ByVal lpPathName As String) As Long at the beginning of the module.

Appreciate any insight or help you can give.

XML:
Sub mCheckMaster()
 MsgBox "CheckMaster"
    If vFileNmChk Like "*Master*" Then
        If StrPtr(vDate) = 0 Then
            MsgBox "The Macro Has Been Canceled"
            GoTo EndMacro
        End If
        vMonth = Abs(Right(vDate, 2))
        Sheets("Cycle").Range("b2").Value = vMonth
        vType = InputBox("Enter S - for Surgical Pathology" & vbCrLf & "         C - for Cytology", "Get Report Type")
        If StrPtr(vType) = 0 Then GoTo EndMacro
        If vType = "S" Or vType = "s" Then
        vService = "Surgical"
        ElseIf vType = "C" Or vType = "c" Then
            vService = "Cytology"
        End If
        Sheets("Cycle").Range("B3").Value = vService
    vFileNm = vDate & " " & vService & " Slide Review Report.xlsm"
MsgBox vFileNm
    ChDrive "L:\"
    ChDir vPathPath
'- - - attempt from code found in google search
'    SetCurrentDirectoryA "\\R04mwvnas21\p&lms\KDG-MPA\Vista Capture Reports\Slide Review\QA Final Reports\"
'- - - - -
    Application.Dialogs(xlDialogSaveAs).Show vFileNm
        Else
    End If
EndMacro:
End Sub

Thanks,
Ken
 
Is the app running this code Excel or Access?
 
O man... I usually am using Access, but this is excel!! So Sorry to do that! I guess I need to repost in excel.
 
O man... I usually am using Access, but this is excel!! So Sorry to do that! I guess I need to repost in excel.
No need. I've moved it for you. Cheers!
 
Code:
Sub Test()
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogSaveAs)

With fd
    .Title = "Provide file name & location"
    'for the initial folder, use the part before the last back slash, and they
    'will therefore end up inside your specified folder
    .InitialFileName = "C:\Users\SuggestedFileName.xlsx" 'whatever

    .Show
End With
End Sub
 
add the Path to your code:

Application.Dialogs(xlDialogSaveAs).Show vPathPath & vFileNm
 

Users who are viewing this thread

Back
Top Bottom