JScriptでWordとPowerPointのプロパティを変更する

まずはWordから。さすがにEXCELの姉妹ソフトだけあってほぼ同じ。ただ、ヘッダ、フッタはセクション単位に設定なのでかなり面倒そうだったので諦めたです。

/*
 * MS-WORDのプロパティを設定する
 * properties: プロパティのDictionary
 */
function word_setting(filename, properties) {
    var word = WScript.CreateObject("Word.Application");
    var document = word.Documents.Open(filename, 1);
    
    // プロパティの設定
    for (var key in properties) {
        var property = document.BuiltinDocumentProperties.Item(key);
        property.Value = properties[key];
    }
    
    document.Save();
    document.Close();
    word.Quit();
}

我らがPowerPointはOpenの引数が異なるのでちょっとつまずきやすい。てゆうか、Write権限のフラグくらい統一してくれや。

/*
 * MS-POWERPOINTのプロパティを設定する
 * properties: プロパティのDictionary
 */
function powerpoint_setting(filename, properties) {
    var powerpoint = WScript.CreateObject("PowerPoint.Application");
    var presentation = powerpoint.Presentations.Open(filename, 0, 0, 0);
    
    // プロパティの設定
    for (var key in properties) {
        var property = presentation.BuiltinDocumentProperties.Item(key);
        property.Value = properties[key];
    }
    
    presentation.Save();
    presentation.Close();
    powerpoint.Quit();
}