Created
September 22, 2015 17:52
-
-
Save kissmygritts/672535341c1a0aa694f8 to your computer and use it in GitHub Desktop.
Window dialogue box interactions with VBA. Select a folder and export to a folder.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function PickFile(title As String, start As String, filter As String) As String | |
'------------------------------------------------ | |
' Purpose: Select file from file dialog | |
'------------------------------------------------ | |
Dim dlg As FileDialog | |
Set dlg = Application.FileDialog(msoFileDialogFilePicker) | |
With dlg | |
.title = title | |
.InitialFileName = start | |
.AllowMultiSelect = False | |
.Filters.Clear | |
.Filters.Add filter, "*." & filter & "*", 1 | |
If .Show = True Then | |
PickFile = .SelectedItems(1) | |
Else | |
Exit Function | |
End If | |
End With | |
End Function | |
Function SaveExportAs(title As String, extension As String) As String | |
'------------------------------------------------ | |
' Purpose: Save As file from file dialog | |
' Further Dev: Default extensions, figure that out. | |
'------------------------------------------------ | |
Dim dlg As FileDialog | |
Set dlg = Application.FileDialog(msoFileDialogSaveAs) | |
With dlg | |
.title = title | |
.InitialFileName = "C:\docs\" & extension | |
If .Show = True Then | |
SaveExportAs = .SelectedItems(1) | |
End If | |
End With | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment