Files
script_dev/機能仕様書作成/Module2.bas
2026-04-06 18:15:12 +09:00

79 lines
1.9 KiB
QBasic
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
Attribute VB_Name = "Module2"
Option Explicit
Sub ExcelFileImport()
Application.ScreenUpdating = False
Dim fd As FileDialog
Dim selectedPath As String
Dim wb As Workbook
Dim ws As Worksheet
Dim sheetList As String
Dim tgtSheet As Worksheet
Set tgtSheet = ActiveSheet
'========================
' ファイル選択ダイアログ
'========================
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.Title = "Excelファイルを選択してください"
.Filters.Clear
.Filters.Add "Excelファイル", "*.xlsx; *.xlsm; *.xls"
.AllowMultiSelect = False
If .Show <> -1 Then Exit Sub
selectedPath = .SelectedItems(1)
End With
'========================
' ファイルパスを C3 に出力
'========================
tgtSheet.Range("C3").Value = selectedPath
'========================
' 出力先初期化
'========================
tgtSheet.Range("C4").MergeArea.ClearContents
sheetList = ""
'========================
' Excelファイルを開く
'========================
Set wb = Workbooks.Open(Filename:=selectedPath, ReadOnly:=True)
'========================
' シート名を連結(セル内改行)
'========================
For Each ws In wb.Worksheets
If sheetList = "" Then
sheetList = ws.Name
Else
sheetList = sheetList & vbLf & ws.Name
End If
Next ws
'MsgBox (sheetList)
'========================
' C5結合セルに出力
'========================
With tgtSheet.Range("C4")
.MergeArea.Value = sheetList
.WrapText = True
End With
'========================
' 後処理
'========================
wb.Close SaveChanges:=False
Set wb = Nothing
Application.ScreenUpdating = True
End Sub