Created
August 28, 2020 03:37
-
-
Save h-mochizuki/b58e4a9119b32e47f85e43c09bfbd62a to your computer and use it in GitHub Desktop.
Excelのシート一覧を表示するvbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Explicit | |
'' ======================================================== | |
'' Excelのシート一覧を表示します | |
'' -------------------------------------------------------- | |
'' 引数: | |
'' ファイルパス | |
'' ======================================================== | |
Dim objFso, fileExcel | |
Set objFso = CreateObject("Scripting.FileSystemObject") | |
fileExcel = objFso.GetAbsolutePathName(WScript.Arguments(0)) | |
Set objFso = Nothing | |
Dim objExcel, objWorkbook, objSheet | |
Set objExcel = CreateObject("Excel.Application") | |
objExcel.Visible = False | |
objExcel.DisplayAlerts = False | |
Set objWorkbook = objExcel.Workbooks.Open(fileExcel, ,True) | |
For Each objSheet in objWorkbook.Worksheets | |
Wscript.Echo objSheet.Name | |
Next | |
objWorkbook.Close | |
objExcel.Quit | |
Set objWorkbook = Nothing | |
Set objExcel = Nothing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
fileExcel で絶対パスを取得している部分だが、Excelを開く際にvbsファイルからの相対パスで判断されるのかファイルが見つからないと言われるので相対パスに変更している。