LoginSignup
1
0

More than 3 years have passed since last update.

GetOpenFilenameのデフォルトフォルダを変更する

Last updated at Posted at 2019-08-09

はじめに

test.xlsm
Sub test()
    Dim file_name As String
    file_name = Application.GetOpenFilename
    Debug.Print file_name
End Sub

を実行した時、ダイアログのデフォルトフォルダは
C:\Users\xxxx\Documents
である。これでもいいけど、デフォルトフォルダは開いているエクセルファイルがある場所の方が使いやすいな~

カレントフォルダを変更するだけ

デフォルトフォルダはカレントフォルダである。つまりカレントフォルダを変更すればOK。

test.xlsm
Sub test()
    Dim file_name As String
    ChDir ThisWorkbook.Path 'ここを追加
    file_name = Application.GetOpenFilename
    Debug.Print file_name
End Sub

※カレントフォルダを変更することで、他のプロセスに影響が出る場合もあるので注意が必要

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0