Sub ExportSheetNamesAndDefinedNames()
Dim ws As Worksheet
Dim nm As Name
Dim FileNum As Integer
Dim Sfx As String
Dim FName As String
' 保存先フォルダを指定
Sfx = ThisWorkbook.Path & "\WorkbookInfo\"
If Dir(Sfx, vbDirectory) = "" Then
MkDir Sfx
End If
' シート名をエクスポート
FName = Sfx & "SheetNames.txt"
FileNum = FreeFile
Open FName For Output As #FileNum
For Each ws In ThisWorkbook.Worksheets
Print #FileNum, ws.Name
Next ws
Close #FileNum
' 名前の定義をエクスポート
FName = Sfx & "DefinedNames.txt"
FileNum = FreeFile
Open FName For Output As #FileNum
For Each nm In ThisWorkbook.Names
Print #FileNum, nm.Name & " - " & nm.RefersTo
Next nm
Close #FileNum
MsgBox "シート名と名前の定義をテキストファイルにエクスポートしました!"
End Sub