Skip to content

Instantly share code, notes, and snippets.

@h-mochizuki
Created August 28, 2020 03:37
Show Gist options
  • Save h-mochizuki/b58e4a9119b32e47f85e43c09bfbd62a to your computer and use it in GitHub Desktop.
Save h-mochizuki/b58e4a9119b32e47f85e43c09bfbd62a to your computer and use it in GitHub Desktop.
Excelのシート一覧を表示するvbs
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
@h-mochizuki
Copy link
Author

fileExcel で絶対パスを取得している部分だが、Excelを開く際にvbsファイルからの相対パスで判断されるのかファイルが見つからないと言われるので相対パスに変更している。

Dim objFso, fileExcel
Set objFso = CreateObject("Scripting.FileSystemObject")
fileExcel = objFso.GetAbsolutePathName(WScript.Arguments(0))
Set objFso = Nothing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment