LoginSignup
1
1

More than 3 years have passed since last update.

【VBScript】任意のエクセルファイルを開いて編集後、名前を付けて保存をする。

Posted at

メモとして残します。

■やり方

with WScript.CreateObject("Excel.Application")
    .DisplayAlerts = False ' アラートダイアログを表示しない。
    Set book = .WorkBooks.Open("開くエクセルファイルのパス")
    Set sheet = book.WorkSheets.Item(1) 'とりあえず1番目のシートを取得

    '変数「sheet」に対して処理など・・・・

    book.Saveas("保存先パス") '.DisplayAlertsがfalseであれば同名ファイルは上書きされる。

    .Quit()  ' Excel.Applicationを破棄
end with

■さいごに

おそらくCOMオブジェクト?を呼びしだしてそのオブジェクトの操作をしているだけなのでVBSで、というよりかは、COMオブジェクトを用いて、エクセルを開いて、編集、名前を付けて保存という表現が正しい気がします。

1
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
1
1