カテゴリー名: [ExcelVBAとOLE 基本概念とセル操作]
// セルの指定とプロパティセット
var fso, bookPath;
var ExlApp, wb, ws;
var xlWorkbookNormal = -4143;
fso = WScript.CreateObject("Scripting.FileSystemObject");
bookPath = fso.GetAbsolutePathName("Book1.xls");
if (fso.FileExists(bookPath)) fso.DeleteFile(bookPath);
ExlApp = WScript.CreateObject("Excel.Application"); // Excelの起動
ExlApp.Visible = true; // Excelを見える状態に
wb = ExlApp.Workbooks.Add(); // Workbookの新規作成
ws = wb.Worksheets(2);
with (ws) {
Name = "第2シート";
Activate;
with (Range("A1")) {
Formula = "=NOW()";
RowHeight = 20;
ColumnWidth = 20;
}
}
wb.SaveAs(bookPath, xlWorkbookNormal);
ExlApp.Quit();
' セルの指定とプロパティセット
Option Explicit
Dim FSO, BookPath
Dim EXLapp, WBobj, WSobj
Const xlWorkbookNormal = -4143
Set FSO = CreateObject("Scripting.FileSystemObject")
BookPath = FSO.GetAbsolutePathName("Book1.xls")
If (FSO.FileExists(BookPath) = True) Then FSO.DeleteFile(BookPath)
Set EXLapp = CreateObject("Excel.Application") ' Excelの起動
EXLapp.Visible = True ' Excelを見える状態に
Set WBobj = EXLapp.Workbooks.Add() ' Workbookの新規作成
Set WSobj = WBobj.Worksheets(2)
With WSobj
.Name = "第2シート"
.Activate
With .Range("A1")
.Formula = "=NOW()"
.RowHeight = 20
.ColumnWidth = 20
End With
End With
WBobj.SaveAs BookPath, xlWorkbookNormal
EXLapp.quit
〜 以上 〜