0
1

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 1 year has passed since last update.

エクセルにボタン用意してVBA(マクロ)実行

Last updated at Posted at 2022-11-28

概要

この記事は…
『エクセルにボタン用意してVBA(マクロ)実行』
なんて全くやったことないよ、な状態向け。

下記のような簡単なサンプル作るところまで書いてるよ。
image.png

やり方

開発タブ

左上『ファイル』。
image.png

左下『オプション』。
image.png

『リボンのユーザー設定』 ⇒ 『開発』にチェック入れる。
image.png

VBA

Alt + F11でVBE開く。

下記のようなコード。
image.png

Option Explicit

Private Function TesterDayon()
    MsgBox "押したなお前!", vbInformation, "通知"
End Function

できる限りカプセル化したいので、今回はシートの中にPrivateで関数を作成しました。

ファイル保存

拡張子はxlsmで保存。

ボタン設置とマクロ登録

『開発』 ⇒ 『挿入』 ⇒ ボタンのアイコン。
image.png

ボタン右クリック ⇒ 『マクロの登録』 。
image.png

hogeee.xlsm!Sheet1.TesterDayon

image.png

ファイル名変更時

ファイル名変更すると『マクロの登録』部分のファイル名も自動で更新される。
(後からファイル名変更してもマクロの登録は書き換えなくてOK)
image.png

ボタン削除

ボタン上右クリックすると下記のような選択状態になる。
そっからDelete押せばOK。
image.png

バージョン

Windows 10 Pro 21H2 OSビルド 19045.2311
Microsoft Excel for Microsoft 365 MSO (バージョン 2210 ビルド 16.0.15726.20188) 32 ビット

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?