CreateMail in Developer - No attachments

NikkNakk

New Member
Joined
Jun 11, 2015
Messages
2
Hi,

I am a beginner when it comes to VBA, I have my spread sheet and I am in Developer trying to add a code for CreateMail.

As of now I have this Function (taken from a different spread sheet):

Function Mail_PDF_Outlook(FileNamePDF As String, StrTo As String, _
StrSubject As String, StrBody As String, Send As Boolean)
Dim OutApp As Object
Dim OutMail As Object

Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next
With OutMail
.To = StrTo
.CC = ""
.BCC = ""
.Subject = StrSubject
.Body = StrBody
.Attachments.Add FileNamePDF
If Send = True Then
.Send
Else
.Display
End If
End With
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing
End Function

And to this Function I have this "Sub":

Sub Mail()


Dim StrTo As String
Dim StrSubject As String
Dim StrBody As String


StrTo = Sheets("GlobalPara").Cells(19, 5)
StrSubject = Sheets("GlobalPara").Cells(20, 5)
StrBody = Sheets("GlobalPara").Cells(21, 5)

Mail , StrTo, StrSubject, StrBody, False

End Sub


Can anyone help me getting the correct Function without PDF attachement and the correct Sub?

thank you.
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
your Mail sub is calling itself, you want to call MAIL_PDF_OUTLOOK

(REMOVE: MAIL,STRTO,STRSUBJ,STRBODY,FALSE)
call Mail_PDF_Outlook(FileNamePDF , StrTo ,
StrSubject , StrBody , false)
 
Upvote 0
thank you ranman256.

I get this error when I change to what you suggested "Compile error: ByRef arbument type mismatch" and it Points to "Sub Mail()". Any idea?

thanks.
 
Upvote 0
if you are passing variables ,you must declare them all as strings. or literals..
Mail_PDF_Outlook "c:\folder\file.pdf","bob@me.com"...

call Mail_PDF_Outlook(strFileNamePDF , StrTo , StrSubject , StrBody , false)
 
Upvote 0

Forum statistics

Threads
1,214,545
Messages
6,120,132
Members
448,947
Latest member
test111

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top