0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

複数のエクセルファイルのシート数を開かずに確認する方法。(動作確認中)

Last updated at Posted at 2024-09-17

以下のスクリプトをテキストエディタにコピーして、count_sheets.vbsという名前で保存します。

count_sheets.vbs
Set objFSO = CreateObject("Scripting.FileSystemObject")
folderPath = "C:\path\to\your\folder" ' ここにフォルダパスを指定
outputFilePath = "C:\path\to\your\output.txt" ' 結果を保存するテキストファイルのパスを指定

' 出力ディレクトリを取得して存在しない場合は作成
If Not objFSO.FolderExists(objFSO.GetParentFolderName(outputFilePath)) Then
    objFSO.CreateFolder(objFSO.GetParentFolderName(outputFilePath))
End If

' 結果ファイルを常に新規作成して書き込み
Set objOutputFile = objFSO.CreateTextFile(outputFilePath, True)

Set objFolder = objFSO.GetFolder(folderPath)
Set objExcel = CreateObject("Excel.Application")

For Each file In objFolder.Files
    If LCase(objFSO.GetExtensionName(file)) = "xlsx" Then
        Set workbook = objExcel.Workbooks.Open(file.Path, , True)
        message = file.Name & ": " & workbook.Sheets.Count & " sheets"
        
        ' コマンドラインに表示
        WScript.Echo message
        
        ' 結果ファイルに書き込み
        objOutputFile.WriteLine message
        
        workbook.Close False
    End If
Next

objExcel.Quit
objOutputFile.Close

C:\path\to\your\folder を確認したいフォルダのパスに置き換えてください。
コマンドラインから次のように実行します。


cscript //nologo count_sheets.vbs


注意点
ExcelがインストールされているWindows環境が必要です。
PowerShellまたはVBSのスクリプト実行が許可されている必要があります。
フォルダ名に日本語を含めると文字コードを気にしなくてはいけないのでアルファベットでの構成を推奨しますが、対処可能なので調べてみてください。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?