Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
2
Help us understand the problem. What is going on with this article?
@hinkymargin

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

More than 1 year has passed since last update.

やりたいこと

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

方法

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

コード

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
2
Help us understand the problem. What is going on with this article?
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
hinkymargin
非IT系の雑用係

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
2
Help us understand the problem. What is going on with this article?