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
oDoc.SaveAs(filepath, Word.WdSaveFormat.wdFormatPDF) 'oDoc.Password="trypw" This one did'nt work 'oDoc.WritePassword = "trypw" This also did'nt work
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)