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

なんか

Posted at
Dim AcrobatApp As Object ' Acrobat.Application
Dim PDFDoc As Object ' Acrobat.Document
Dim FilePath As String
Dim OldPassword As String
Dim NewPassword As String

' パスワードを設定したい既存のPDFファイルのパスを指定
FilePath = "C:\フォルダ\既存のPDFファイル.pdf"

' 既存のPDFファイルのパスワード(設定されている場合)と新しいパスワードを指定
OldPassword = "" ' 既存のパスワードがない場合は空文字列を指定
NewPassword = "新しいパスワード"

' Acrobatアプリケーションを起動
Set AcrobatApp = CreateObject("AcroExch.App")
AcrobatApp.Show ' Acrobatのウィンドウを表示(不要な場合はコメントアウト)

' PDFを開く
Set PDFDoc = CreateObject("AcroExch.PDDoc")
If PDFDoc.Open(FilePath, OldPassword) Then
    ' パスワードを設定
    If PDFDoc.SetSecurity(1, "", NewPassword, 0, "", "") Then ' 1: パスワード保護, 0: 印刷の制限なし
        ' パスワード付きで上書き保存
        If PDFDoc.Save(1, FilePath) = False Then
            MsgBox "PDFの保存に失敗しました。", vbExclamation
        End If
        ' PDFを閉じる
        PDFDoc.Close
    Else
        MsgBox "パスワードの設定に失敗しました。", vbExclamation
    End If
Else
    MsgBox "PDFファイルのオープンに失敗しました。", vbExclamation
End If

' Acrobatを終了
AcrobatApp.Exit
Set AcrobatApp = Nothing

MsgBox "PDFファイルにパスワードを付与しました。", vbInformation
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?