Reputation: 11
I'm fairly new to VBA and I'm having trouble writing a macro that creates an email with my signature already attached. Can someone let me know what exactly is wrong with my code and how I can fix it?
Sub SendFIleAsAttachment()
Dim OLApp As Outlook.Application
Dim OLMail As Object
signature As String
Set OLApp = New Outlook.Application
Set OLMail = OLApp.CreateItem(0)
OLApp.Session.Logon
With OLMail
.Display
End With
signature = OMail.Body
With OMail
.To = "email"
.CC = "email"
.BCC = ""
.Subject = "New Copy Proofing Request"
.Body = "body text. Thanks!" & vbNewLine & signature
.Attachments.Add ActiveWorkbook.FullName
End With
Set OLMail = Nothing
Set OLApp = Nothing
End Sub
Upvotes: 1
Views: 162
Reputation: 43595
You are misspelling OLMail
and OMail
and you are missing the word Dim
once in your code. To fix this kind of grammer mistakes, follow the good practice inserting Option Explicit
on the top of your Module/Worksheet - What do Option Strict and Option Explicit do?
Sub SendFIleAsAttachment()
Dim OLApp As Outlook.Application
Dim OLMail As Object
Dim signature As String
Set OLApp = New Outlook.Application
Set OLMail = OLApp.CreateItem(0)
With OLMail
.Display
End With
signature = OLMail.Body
With OLMail
.To = "email"
.CC = "email"
.BCC = ""
.Subject = "New Copy Proofing Request"
.Body = "body text. Thanks!" & vbNewLine & signature
End With
End Sub
Upvotes: 3