Click here to Skip to main content
16,016,712 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How do i set a password convered file word to pdf then protect password. i tried some codes but did'nt work , this is made from vb.net

filepath = "C:\Users\" & Environ("Username") & "\Desktop\WindowsApplication2\Payslips\Payslip " & item.SubItems.Item(1).Text & " " & Format(dtpPayoutDate.Value, "MM-dd-yyyy") & ".pdf"


           oDoc.SaveAs(filepath, Word.WdSaveFormat.wdFormatPDF)


           oWord.Quit(False)
           oWord = Nothing

           If item.SubItems.Item(21).Text = "" Or IsDBNull(item.SubItems.Item(21).Text) Or item.SubItems.Item(21).Text Is Nothing Then

           Else
               Dim OutlookMessage As outlook.MailItem
               Dim AppOutlook As New outlook.Application
               Dim filereader1 As String = My.Computer.FileSystem.ReadAllText("C:\Users\" & Environ("Username") & "\Desktop\WindowsApplication2\email template.txt")
               Try
                   OutlookMessage = AppOutlook.CreateItem(outlook.OlItemType.olMailItem)
                   Dim Recipents As outlook.Recipients = OutlookMessage.Recipients
                   Recipents.Add(item.SubItems.Item(21).Text)
                   OutlookMessage.Subject = "Payslip " & Format(dtpPayoutDate.Value, "MM-dd-yyyy")
                   OutlookMessage.Body = filereader1
                   OutlookMessage.BodyFormat = outlook.OlBodyFormat.olFormatHTML
                   OutlookMessage.Attachments.Add(filepath)
                   OutlookMessage.Send()
               Catch ex As Exception
                   MessageBox.Show("Mail could not be sent") 'if you dont want this message, simply delete this line
               Finally
                   OutlookMessage = Nothing
                   AppOutlook = Nothing
               End Try
           End If


What I have tried:

I tried putting this under
oDoc.SaveAs(filepath, Word.WdSaveFormat.wdFormatPDF)
'oDoc.Password="trypw" This one did'nt work
'oDoc.WritePassword = "trypw" This also did'nt work

but nothing happen.
Posted
Updated 22-Jul-19 4:27am

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900