Consulting

Results 1 to 2 of 2

Thread: VB Script word in pdf including password

  1. #1
    VBAX Newbie
    Joined
    Sep 2022
    Posts
    1
    Location

    VB Script word in pdf including password

    Hy everyone.
    Need one script /Macro to save a word doc to a pdf with one password protection (should be predefined). Is there any way.
    I m using win 10/office 2019 and installed adobe Dc.
    I tryed several options and found only 2 macro for saving a word file with passwd ad follow:

    Sub Passwort()
    ' Passwort Makro
    Set aDoc = ActiveDocument
    If aDoc.ProtectionType <> wdNoProtection Then
     aDoc.Unprotect
     Selection.InsertBefore "XY"
     aDoc.Protect Type:=wdAllowOnlyRevisions, Password:=strPassword
    End If
    End Sub
    
    Sub Passwed_Setzten()
    'Passwed_Setzten Makro
    With ActiveDocument
    .ReadOnlyRecommended = True
    .Password = "XY"
    .WritePassword = "XY"
    .RemovePersonalInformation = False
    .RemoveDateAndTime = False
    ' Author setzen
    .BuiltInDocumentProperties(3) = "XY"
    End With
    With Options
    .WarnBeforeSavingPrintingSendingMarkup = False
    .StoreRSIDOnSave = True
    .ShowMarkupOpenSave = True
    End With
    End Sub
    
    'for saving to a pdf file I m using folowing script, but this is not password protected
    'Directly save Word file as Pdf and aumatically open it.
    
    Sub DirectlySaveDocxToPdf()
      Dim objDoc As Document
    Set objDoc = ActiveDocument
      objDoc.ExportAsFixedFormat _
        OutputFileName:=Replace(objDoc.FullName, ".docx", ".pdf"), _
        ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:=wdExportOptimizeForPrint, _
        Range:=wdExportAllDocument, Item:=wdExportDocumentContent
    End Sub
    
    Sub Direct_Save_pdf()
    End Sub
    Many thanks for your great help
    Last edited by Aussiebear; 09-01-2022 at 05:47 AM. Reason: Added code tags to supplied code

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    VBA in MS Office cannot password-protect PDFs.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •