Email doc

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
 
T

Tinytall

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
 
D

David Sisson

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?
 
T

Tinytall

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!
 
D

David Sisson

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top