Trying to email from excel. I got this from TommyGun...
Sub email()
Dim objOut As Outlook.Application
Dim objTask As Outlook.TaskItem
Dim blnCrt As Boolean
On Error GoTo CreateOutlook
Set objOut = GetObject(, "Outlook.Application")
CreateItem:
On Error GoTo 0
Set objTask = objOut.CreateItem(olTaskItem)
With objTask
.Assign
.Subject = "Test"
.Body = "This is a test email from excel, let me know if it worked...Austin " '& Format(Now + 10, "mm/dd/yy")
'.DueDate = CDate(Now + 10)
.Recipients.Add ("email@domain.com")
.Send
End With
If blnCrt = True Then objOut.Quit
Set objTask = Nothing
Set objOut = Nothing
Exit Sub
CreateOutlook:
Set objOut = CreateObject("Outlook.Application")
blnCrt = True
Resume CreateItem
End Sub
However, I get an error right off the bat with the line
'Dim objOut As Outlook.Application'
Error message is "User-defined type not defined"
I checked another post that said in Tools....References make sure 'Microsoft Office 9.0 Object Library' is checked. It is but it still doesn't work. What is the solution?
Sub email()
Dim objOut As Outlook.Application
Dim objTask As Outlook.TaskItem
Dim blnCrt As Boolean
On Error GoTo CreateOutlook
Set objOut = GetObject(, "Outlook.Application")
CreateItem:
On Error GoTo 0
Set objTask = objOut.CreateItem(olTaskItem)
With objTask
.Assign
.Subject = "Test"
.Body = "This is a test email from excel, let me know if it worked...Austin " '& Format(Now + 10, "mm/dd/yy")
'.DueDate = CDate(Now + 10)
.Recipients.Add ("email@domain.com")
.Send
End With
If blnCrt = True Then objOut.Quit
Set objTask = Nothing
Set objOut = Nothing
Exit Sub
CreateOutlook:
Set objOut = CreateObject("Outlook.Application")
blnCrt = True
Resume CreateItem
End Sub
However, I get an error right off the bat with the line
'Dim objOut As Outlook.Application'
Error message is "User-defined type not defined"
I checked another post that said in Tools....References make sure 'Microsoft Office 9.0 Object Library' is checked. It is but it still doesn't work. What is the solution?