Bye Bye Moore

PoCソルジャーな零細事業主が作業メモを残すブログ

VBAでダイアログ形式でファイルを開きパスを取得

みんな大好きExcel
今回はExcelで実行できるVBAでダイアログ形式でファイルを開きパスを取得の話。

実際のところ

まずは写経。
ファイルが読み込まれるとダイアログがでてTextファイルがデフォ指定でチェックできるもの。

fileToOpen = Application _ 
.GetOpenFilename("Text Files (*.txt), *.txt")
If fileToOpen <> False Then 
 MsgBox "Open " & fileToOpen 
End If

ボタンに連動させる場合

Private Sub CommandButton1_Click()

Filename = Application.GetOpenFilename() 
MsgBox Filename

End Sub

f:id:shuzo_kino:20210525223313p:plain