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.

Excel VBAでパスワード保護されたブックか確認する

Posted at

Excel VBAでパスワード保護されたブックか確認する方法

Excel VBAでパスワード保護されたブックを開こうとするとパスワード入力画面が表示され、自動的なマクロの実行が妨害されてしまいます。
パスワード保護されたブックを除外して、自動的な処理を継続したい場合には、次のようにして、ブックがパスワード保護されているかを確認できます。

Sample.txt
Function IsPasswordProtected(ByVal FileName As String) As Boolean
    Dim wb As Workbook
    On Error Resume Next
    'パスワード入力ダイアログがでないようにダミーのパスワードを指定する。
    Set wb = Workbooks.Open(FileName, , True, , "THIS_PASSWORD_NEVER_MATCHES")
    On Error Goto 0
    If wb Is Nothing Then
        IsPasswordProtected = True
    Else
        wb.Close False
        Set wb = Nothing
    End If
End Function
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?