Terje Fritzman
New Member
Hello,
I've managed to get my excel sheet exported as a PDF and I've been able to attach it into outlook as an attachment if I use a full path to the file, but when I get a little more advanced and make the file name: "ActiveWorkbook.Path & "\Endringsmelding " & Cells(5, 27)", the attachment no longer gets attached in the mail.
Anyone know why my code suddenly doesn't work anymore?
Code:
>>> use code - tags <<<
I've managed to get my excel sheet exported as a PDF and I've been able to attach it into outlook as an attachment if I use a full path to the file, but when I get a little more advanced and make the file name: "ActiveWorkbook.Path & "\Endringsmelding " & Cells(5, 27)", the attachment no longer gets attached in the mail.
Anyone know why my code suddenly doesn't work anymore?
Code:
>>> use code - tags <<<
Code:
Private Sub CommandButton1_Click()
'Make PDF and attach in Outlook
ChDir ActiveWorkbook.Path
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
ActiveWorkbook.Path & "\Endringsmelding " & Cells(5, 27), OpenAfterPublish:=True
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
Dim myAttachments As Object
On Error Resume Next
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
Set myAttachments = xOutMail.Attachments
xMailBody = "Hei," & vbNewLine & vbNewLine & _
"Her kommer endringsmeldingen ang. ......" & vbNewLine & vbNewLine & _
"Kunne jeg ha fått tilbake en signert versjon?" & vbNewLine & vbNewLine
On Error Resume Next
With xOutMail
.To = Cells(5, 41).Value
.Cc = ""
.BCC = ""
.Subject = "Endringsmelding"
.Body = xMailBody
.myAttachments.Add (ActiveWorkbook.Path & "\Endringsmelding " & Cells(5, 27))
.Display 'or use .Send
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
Last edited by a moderator: