S
Sean
I have code (below) to generate an email in Word, but I get an error: 'User
defined type not defined'. I believe it is referring to oOutlookApp and
oItem. I can't figure out what the issue is though. Thanks for the help!
***
Sub Email_manager()
Application.ScreenUpdating = False
ActiveDocument.Save
'email report
Application.DisplayAlerts = False
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
On Error Resume Next
If Len(ActiveDocument.Path) = 0 Then
MsgBox "Document needs to be saved first"
Exit Sub
End If
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If
Set oItem = Outlook.Application.CreateItem(olMailItem)
FileName = ActiveDocument.CustomDocumentProperties("WeekEndingDate").Value
Consult = ActiveDocument.CustomDocumentProperties("ConsultLast").Value
With oItem
.To = ActiveDocument.CustomDocumentProperties("ManagerEmail").Value
.Subject = "SCWU (" & Consult & ") & FileName"
'Add the document as an attachment, you can use the .displayname property
'to set the description that's used in the message
.Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue, _
DisplayName:="Document as attachment"
.Body = ActiveDocument.CustomDocumentProperties("ManagerName").Value &
"," & vbCrLf & vbCrLf & "Attached is my SCWU for week ending " &
ActiveDocument.CustomDocumentProperties("WeekEndingDate").Value & " ." &
vbCrLf _
& "Please let me know if you have any questions or comments." &
vbCrLf & vbCrLf & "Thanks," & vbCrLf &
ActiveDocument.CustomDocumentProperties("ConsultFirst").Value
'.Send
.Display
On Error Resume Next
End With
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
defined type not defined'. I believe it is referring to oOutlookApp and
oItem. I can't figure out what the issue is though. Thanks for the help!
***
Sub Email_manager()
Application.ScreenUpdating = False
ActiveDocument.Save
'email report
Application.DisplayAlerts = False
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
On Error Resume Next
If Len(ActiveDocument.Path) = 0 Then
MsgBox "Document needs to be saved first"
Exit Sub
End If
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If
Set oItem = Outlook.Application.CreateItem(olMailItem)
FileName = ActiveDocument.CustomDocumentProperties("WeekEndingDate").Value
Consult = ActiveDocument.CustomDocumentProperties("ConsultLast").Value
With oItem
.To = ActiveDocument.CustomDocumentProperties("ManagerEmail").Value
.Subject = "SCWU (" & Consult & ") & FileName"
'Add the document as an attachment, you can use the .displayname property
'to set the description that's used in the message
.Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue, _
DisplayName:="Document as attachment"
.Body = ActiveDocument.CustomDocumentProperties("ManagerName").Value &
"," & vbCrLf & vbCrLf & "Attached is my SCWU for week ending " &
ActiveDocument.CustomDocumentProperties("WeekEndingDate").Value & " ." &
vbCrLf _
& "Please let me know if you have any questions or comments." &
vbCrLf & vbCrLf & "Thanks," & vbCrLf &
ActiveDocument.CustomDocumentProperties("ConsultFirst").Value
'.Send
.Display
On Error Resume Next
End With
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub