[エクセルを起動する]
エクセルを起動して簡単な数式を出力後、保存して終了します。
【ソースコード】
[tips0171.vbs]
Option Explicit
On Error Resume Next
Dim objXlApp
Dim objXlBook
Dim objXlSheet
Set objXlApp = WScript.CreateObject("Excel.Application")
If Err.Number = 0 Then
Set objXlBook = objXlApp.Workbooks.Add
If Err.Number = 0 Then
Set objXlSheet = objXlBook.Worksheets(1)
If Err.Number = 0 Then
objXlSheet.Cells(1, 1).Value = 123
objXlSheet.Cells(1, 2).Value = "+"
objXlSheet.Cells(1, 3).Value = 456
objXlSheet.Cells(1, 4).Value = "="
objXlSheet.Cells(1, 5).Formula = "=A1+C1"
objXlSheet.SaveAs "C:\Temp\Test.xls"
objXlApp.Quit
Else
WScript.Echo "エラー:" & Err.Description
End If
Else
WScript.Echo "エラー:" & Err.Description
End If
Else
WScript.Echo "エラー:" & Err.Description
End If
Set objXlSheet = Nothing
Set objXlBook = Nothing
Set objXlApp = Nothing