「Excel VBA ドライブ、ディレクトリを指定してファイルを開くダイアログを表示」の版間の差分
ナビゲーションに移動
検索に移動
| 1行目: | 1行目: | ||
| − | ==Excel VBA | + | ==[[Excel VBA ドライブ、ディレクトリを指定してファイルを開くダイアログを表示]]する== |
[[Excel VBA]] | | [[Excel VBA]] | | ||
| 23行目: | 23行目: | ||
Dim results() As String | Dim results() As String | ||
| − | + | [[R]]eDim results(0) | |
outPath = ActiveWorkbook.Path | outPath = ActiveWorkbook.Path | ||
| 29行目: | 29行目: | ||
Call ChDir(outPath) | Call ChDir(outPath) | ||
| − | selFile = Application.GetOpenFilename(" | + | selFile = Application.GetOpenFilename("[[Excel]]ファイル (*.xlsx),*.xlsx)", MultiSelect:=True) |
If IsArray(selFile) Then | If IsArray(selFile) Then | ||
| − | + | [[R]]eDim results(UBound(selFile)) | |
For i = 0 To UBound(selFile) - 1 | For i = 0 To UBound(selFile) - 1 | ||
results(i) = CStr(selFile(i + 1)) | results(i) = CStr(selFile(i + 1)) | ||
2020年2月16日 (日) 04:25時点における最新版
Excel VBA ドライブ、ディレクトリを指定してファイルを開くダイアログを表示する
1ファイルのみ選択
Dim selFile As Variant
Dim outPath As String
outPath = "f:\work\data"
Call ChDrive(Left$(outPath, 2))
Call ChDir(outPath)
selFile = Application.GetOpenFilename("ログファイル (*.log),*.log)", , "")
If selFile = False Then
Call MsgBox("ファイルが選択されませんでした", vbInformation)
Exit Sub
End If
複数ファイル選択
Dim selFile As Variant Dim outPath As String Dim i As Integer Dim results() As String ReDim results(0) outPath = ActiveWorkbook.Path Call ChDrive(Left$(outPath, 2)) Call ChDir(outPath) selFile = Application.GetOpenFilename("Excelファイル (*.xlsx),*.xlsx)", MultiSelect:=True) If IsArray(selFile) Then ReDim results(UBound(selFile)) For i = 0 To UBound(selFile) - 1 results(i) = CStr(selFile(i + 1)) Next Else Call MsgBox("ファイルが選択されませんでした", vbInformation) End If ChooseFiles = results
© 2006 矢木浩人