D
David Sisson
I email from a userform, but maybe you can adapt the code.
Private Sub cmdEmail_Click()
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
Dim MyPath As String
'userform to add text to the body.
ufAddMessage.Show
'Change caption title to indicate progress.
ufMoveFiles.Caption = "Sending Files to " & EmailName
MyPath = GlLogPath
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 = oOutlookApp.CreateItem(olMailItem)
With oItem
.To = EmailName
.Subject = "Subject text goes here."
.Body = AddMessage$ 'from ufAddMessage
'Adds files from a listbox
'Add the document as an attachment.
'You can use the .displayname property
'to set the description that's used in the message body.
'ufMoveFiles.ListBox1.Selected().SendMail
For A = 1 To Counter
If ufMoveFiles.ListBox1.Selected(A) Then
.Attachments.Add Source:=MyPath + FileList(A), Type:=olByValue,
_
DisplayName:=FileList(A)
End If
Next
.Send
End With
If bStarted Then
oOutlookApp.Quit
End If
Set oItem = Nothing
Set oOutlookApp = Nothing
'Change caption to indicate process done.
ufMoveFiles.Caption = "Choose Option"
End Sub
Private Sub cmdEmail_Click()
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
Dim MyPath As String
'userform to add text to the body.
ufAddMessage.Show
'Change caption title to indicate progress.
ufMoveFiles.Caption = "Sending Files to " & EmailName
MyPath = GlLogPath
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 = oOutlookApp.CreateItem(olMailItem)
With oItem
.To = EmailName
.Subject = "Subject text goes here."
.Body = AddMessage$ 'from ufAddMessage
'Adds files from a listbox
'Add the document as an attachment.
'You can use the .displayname property
'to set the description that's used in the message body.
'ufMoveFiles.ListBox1.Selected().SendMail
For A = 1 To Counter
If ufMoveFiles.ListBox1.Selected(A) Then
.Attachments.Add Source:=MyPath + FileList(A), Type:=olByValue,
_
DisplayName:=FileList(A)
End If
Next
.Send
End With
If bStarted Then
oOutlookApp.Quit
End If
Set oItem = Nothing
Set oOutlookApp = Nothing
'Change caption to indicate process done.
ufMoveFiles.Caption = "Choose Option"
End Sub