0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

備忘録 - ワークブック・シートの指定・操作【VBA】

Posted at

ワークブックの指定方法

ThisWorkBook 'マクロが書かれているワークブック
ActiveWorkBook '現在アクティブのワークブック
Workbooks("ワークブック名.xlsm") 'パスは含めず、拡張子も記載する。ワークブックを開いていないと指定できない。

ワークシートの指定

コードネーム 'コードネームの前でワークブックを指定しない
Worksheets("ワークシート名") 'タブの名前を用いる(ワークブックを指定可)
ActiveSheet '現在アクティブのワークシート

現在アクティブのワークブックの名前・パスを調べる

ワークブック.Name 'ファイル名を表示
ワークブック.Path  'ファイルまでのパスを表示
ワークブック.FullName 'パスとファイル名を表示

ワークブックを開く

Application.Workbooks.Open "パスとファイル名"

ワークブックを閉じる

ワークブック.Close

'保存して閉じる
ワークブック.Close SaveChanges:=True

ワークブックを保存する

ワークブック.Save

ワークブックを新たに追加する

Addメソッド

Dim NewBook As Workbook
Set NewBook = Workbooks.Add

ワークシートを新たに追加する

Addメソッド

Dim NewSheet As Worksheet
Set NewSheet = NewSheets.Add

'名前を付ける
NewSheet.Name = "名前"
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?