【VBA】MkDirでフォルダを作る
記事更新日:2022-11-04
![サムネイル](https://tsukiusagi.biz/wp-content/uploads/2022/09/vba.png)
MkDir パス
![](https://i0.wp.com/tsukiusagi.biz/wp-content/uploads/2022/01/rabbit1-2.png?resize=150%2C150&ssl=1)
Make Directory という意味
フォルダのことを「ディレクトリ」とも呼ぶ
MkDir でフォルダ作成
フォルダ作成後、フォルダのパスを返す
![](https://i0.wp.com/tsukiusagi.biz/wp-content/uploads/2022/01/rabbit3.png?resize=150%2C150&ssl=1)
引数 path の中身は、ThisWorkbook.Path など
Public Function MakeFolderPath( _
ByVal path As Variant, _
ByVal folderName As String) As Variant
folderPath = path & "¥" & folderName
Dim folderPath As Variant
'フォルダが存在していない場合のみ、フォルダ作成
If NotExistsFolder(folderPath) Then MkDir folderPath
'フォルダ作成してないときは中身が空になる
MakeFolderPath = folderPath
End Function
'フォルダがすでに存在していないことを確認
Private Function NotExistsFolder(ByVal myPath As String) As Boolean
NotExistsFolder = False
If Dir(myPath, vbDirectory) = "" Then NotExistsFolder = True
End Function
![](https://i0.wp.com/tsukiusagi.biz/wp-content/uploads/2022/01/rabbit1-2.png?resize=150%2C150&ssl=1)
パスを返す目的は、メッセージ表示に使ったりとか、フォルダを開いたりとか
関連記事
2022-11-04
編集後記:
この記事の内容がベストではないかもしれません。