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
I get a User-defined type not defined with the second Dim statement. I'm not
a coder by nature, so this doesn't mean anything to me.
I create a VB button, and simply stick your code in (with changes to get
specific results, such as email address, etc)... I'm not sure if I need to
define something somehow that I don't understand (obviously).
Thanks
Eric
> I email from a userform, but maybe you can adapt the code.
>
[quoted text clipped - 57 lines]
> ufMoveFiles.Caption = "Choose Option"
> End Sub
David Sisson - 11 Jul 2005 21:54 GMT
>I'm not a coder by nature, so this doesn't mean anything to me.
Yeah, me too. But I have several ref books and know how to use search!
:-)
Hmm...
You do have Outlook installed?
(OK I'm grabbing at straws here) Is the Tools->Reference-> Office ?.0
Object model selected?
Will anyone else offer a solution?
Tinytall - 12 Jul 2005 19:33 GMT
I've checked all settings and nothing seems out of whack. I never found the
"(OK I'm grabbing at straws here) Is the Tools->Reference-> Office ?.0
Object model selected?" that you referenced. I have decided to just leave it
as a routing slip as offered before, and what I've found to work. No sense in
killing myself over this if there is a duct tape way to make it work.
Thanks for helping!
> >I'm not a coder by nature, so this doesn't mean anything to me.
>
[quoted text clipped - 9 lines]
>
> Will anyone else offer a solution?
David Sisson - 12 Jul 2005 20:05 GMT
I'll try to be more specific.
In the VB Editor. Tools->Reference->Microsoft Office 8.0 (or 9.0, or
10.0, etc.) Object Model. It should be at the top of the listbox and
the check box on the left is selected.
If not, scroll down the list until you find it, and select it.
Then try the code.
David