How to attach PDF to preformatted email

How to attach PDF to preformatted email

Jason.Rugg
Collaborator Collaborator
287 Views
3 Replies
Message 1 of 4

How to attach PDF to preformatted email

Jason.Rugg
Collaborator
Collaborator

I have a rule that pdf's a drawing and saves it next to the source file with the same name, is there a way to automatically then attach that pdf to a preformatted email message?

0 Likes
288 Views
3 Replies
Replies (3)
Message 2 of 4

tyler.warner
Advocate
Advocate

@Jason.Rugg try this. It will use the PDF with the same name & location as the open drawing. You said you had a rule to accomplish that already so it's not included in this iLogic rule to create the email & attach the PDF.

 

Sub Main
	
	oOApp = CreateObject("Outlook.Application")
	oOMail = oOApp.CreateItem(0)
	
	Dim oDocument As Document = ThisApplication.ActiveDocument
    Dim oFileName As String = oDocument.DisplayName.Replace(".idw", "")
	
	oMessageBody = "<p style='font-family:calibri;font-size:16'>" & "Hello," & "<br><br>" & vbNewLine & vbNewLine & _	
	"This is the message body of the email for drawing: " & oFileName
				   
	' Create email.
	With oOMail
	    .bodyformat=2
	    .To = ""
	    .CC = ""
	    .BCC = ""
	    .Subject = "This is an email with a PDF of drawing: " & oFileName
	    .Display
	End With
	
	' Add email message.
	With oOMail
		.HTMLbody = oMessageBody & vbNewLine & .HTMLBody ' Add the signature without losing the HTML-formatting.
	End With
	
	' Add PDF.
	Try
		With oOMail
	    .Attachments.Add(oDocument.FullFileName.Replace(".idw", ".pdf"))
		End With
	Catch
		MsgBox("Unable to attach the PDF.")
	End Try
	
End Sub

 

If this solved your problem or answered your question, please click ACCEPT SOLUTION.
If this helped you, please click LIKE.
0 Likes
Message 3 of 4

Jason.Rugg
Collaborator
Collaborator

@tyler.warner That is sort of working, I get the following errors when running the rule. Any suggestions?

JasonRugg_0-1663782055145.png

 

0 Likes
Message 4 of 4

tyler.warner
Advocate
Advocate

@Jason.Rugg  Sorry about that, here:

 

Sub Main

        Dim oOApp As Object = CreateObject("Outlook.Application")
        Dim oOMail As Object = oOApp.CreateItem(0)

        Dim oDocument As Document = ThisApplication.ActiveDocument
        Dim oFileName As String = oDocument.DisplayName.Replace(".idw", "")

        Dim oMessageBody As String = "<p style='font-family:calibri;font-size:16'>" & "Hello," & "<br><br>" & vbNewLine & vbNewLine &
    "This is the message body of the email for drawing: " & oFileName

        ' Create email.
        With oOMail
            .bodyformat = 2
            .To = ""
            .CC = ""
            .BCC = ""
            .Subject = "This is an email with a PDF of drawing: " & oFileName
            .Display
        End With

        ' Add email message.
        With oOMail
            .HTMLbody = oMessageBody & vbNewLine & .HTMLBody ' Add the signature without losing the HTML-formatting.
        End With

        ' Add PDF.
        Try
            With oOMail
                .Attachments.Add(oDocument.FullFileName.Replace(".idw", ".pdf"))
            End With
        Catch
            MsgBox("Unable to attach the PDF.")
        End Try

End Sub

 

If this solved your problem or answered your question, please click ACCEPT SOLUTION.
If this helped you, please click LIKE.
0 Likes