Help us understand the problem. What is going on with this article?

Excel VBA で「マクロが実行できる状態」でないとファイルの中身を見れないようにする

やりたいこと

フォームから入力をさせたい等、マクロを実行できる状態でのみ操作を許可したい。

方法

「マクロを有効にしてください」と書いたシートを用意して、他のシートを非表示にする。
ファイルオープン時、ファイル保存時に表示するシートを切り替えるようにする。

コード

ThisWorkbook
'Sheet1:「マクロを有効にしてください」と書いたシート
'Sheet2:何かいろいろするシート
Private Sub Workbook_Open()
    Sheet2.Visible = xlSheetVisible
    Sheet1.Visible = xlSheetVeryHidden
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Sheet1.Visible = xlSheetVisible
    Sheet2.Visible = xlSheetVeryHidden
End Sub

Private Sub Workbook_AfterSave(ByVal Success As Boolean)
    Sheet2.Visible = xlSheetVisible
    Sheet1.Visible = xlSheetVeryHidden
End Sub
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした