Skip to content

Instantly share code, notes, and snippets.

@taka2
Created March 4, 2011 07:46
Show Gist options
  • Select an option

  • Save taka2/854317 to your computer and use it in GitHub Desktop.

Select an option

Save taka2/854317 to your computer and use it in GitHub Desktop.
Dim excelFileName, excelObj, workbookObj, worksheetObj
' 引数チェック
If WScript.Arguments.Count <> 1 Then
msgbox "Usage: neatexcel.vbs [Excel FileName]"
WScript.Quit(1)
End If
excelFileName = WScript.Arguments(0)
' Excel起動
Set excelObj = CreateObject("Excel.Application")
Set workbookObj = excelObj.Workbooks.Open(excelFileName)
' 各シートのCells(1, 1)を選択する
For Each worksheetObj In workbookObj.Sheets
worksheetObj.Select
worksheetObj.Cells(1, 1).Select
Next
' 先頭のシートを選択する
workbookObj.Sheets(1).Select
' 上書き保存して閉じる
workbookObj.Save()
workbookObj.Close()
excelObj.Quit()
' Excel終了
msgbox "done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment