VBA Open to a directory on my computer

daniels012

Well-known Member
Joined
Jan 13, 2005
Messages
5,219
What code can I enter to open A DIALOG WINDOW to a specific folder?

I need to open a SaveAs Dialog window to a specific directory(folder).

Is this possible, not knowing any of the beginning part, but only knowing the folder name itself? Mine is called: LeadFolder

Application.Dialog etc. etc. c:\something\something\something\LeadFolder

Please any help on this is greatly appreciated!


Michael D

I have this on thread on VBA Express as well since it is VBA based stuff!
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Try setting: InitialFilename in GetSaveAsFilename

Code:
Sub test()
    Dim filex As Variant
    filex = Application.GetSaveAsFilename(InitialFilename:="c:\temp\xxx\", _
            FileFilter:="microsoft excel files (*.xls), *.xls")
    If filex <> False Then MsgBox "File Saved as " & filex
End Sub
 
Upvote 0
Ok, here's a second attempt:

Code:
Sub Test()
    strStartPath = "C:\temp\"  'start folder
    strTargetDir = "ffff"   ' target subfolder
    ListFolder strStartPath, strTargetDir
End Sub
Sub ListFolder(ByVal sFolderPath As String, sTarget)
    Dim FS
    Dim FSfolder
    Dim subfolder
    Dim i As Integer
    Dim filex As Variant
    Set FS = CreateObject("Scripting.FileSystemObject")
    Set FSfolder = FS.GetFolder(sFolderPath)
     On Local Error Resume Next
    For Each subfolder In FSfolder.SubFolders
        Debug.Print Mid(subfolder, InStrRev(subfolder, "\") + 1)
        If Mid(subfolder, InStrRev(subfolder, "\") + 1) = sTarget Then
            filex = Application.GetSaveAsFilename(InitialFilename:=subfolder & "\", _
                    FileFilter:="microsoft excel files (*.xls), *.xls")
            If filex <> False Then
                Application.SaveWorkspace filex
                MsgBox "File Saved as: " & filex
            End If
            Set FS = Nothing
            Set FSfolder = Nothing
            Exit Sub
        End If
        DoEvents
        i = i + 1
        ListFolder subfolder, sTarget
    Next subfolder
    Set FS = Nothing
    Set FSfolder = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,762
Messages
6,126,736
Members
449,334
Latest member
moses007

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top