- Back to Home »
- VBA »
- [VBA] File_folder_dialog
Friday, November 29, 2019
Option Explicit
Sub SelectFile_dialog()
Dim myFile As String
' myFile = Application.GetOpenFilename() 'Or below
myFile = Application.GetOpenFilename("CSVファイル,*.csv, All, *.*") 'CSVファイル(*.csv) OR All(*.*)
If myFile <> "False" Then
Debug.Print "Open file " & myFile
Else
Debug.Print "Cancel"
End If
End Sub
Sub SaveFile_dialog()
Dim fileSaveName As String
fileSaveName = Application.GetSaveAsFilename( _
fileFilter:="Text Files, *.txt, All, *.*")
If fileSaveName <> "False" Then
'OK
Debug.Print "Save as " & fileSaveName
Else
Debug.Print "Cancel"
End If
End Sub
Sub SelectFolder_dialog()
Dim sFolder As String
With Application.FileDialog(msoFileDialogFolderPicker)
' .Title = "Select a Folder"
' .InitialFileName = "C:\Windows\"
If .Show = -1 Then ' if OK is pressed
sFolder = .SelectedItems(1)
End If
End With
If sFolder <> "" Then ' if a file was chosen
' *********************
' put your code in here
' *********************
Debug.Print "Open: " & sFolder
' Open: D:\Forex
' Open: D:\dockerpi
Else
Debug.Print "Cancel"
End If
End Sub