Send as attachment

C

Charles Kenyon

I am trying to put a macro into a questionnaire to send it back to me as an
attachment. I've read
http://www.word.mvps.org/FAQs/InterDev/SendMail.htm. I am trying to use the
SendDocumentAsAttachment procedure
and I am getting an error at the line:
Dim oOutlookApp As Outlook.Application

The error message is "User defined type not defined."

Word (and Outlook 2003)

--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide


--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
T

Tony Jollans

If it was anybody else I would say: do you have reference to the Outlook
Type Library? Or do you have it but, perhaps, a missing library higher up
the chain. I can't think of any other reason so, as you don't explicitly say
so, let me be the first to ask the obvious.
 
C

Charles Kenyon

Might be obvious to some, but not to me. No, I do not unless it is installed
by default when you install Office with vba. I am sure that the people I'm
sending it to will not, either, so I'm using the routing slip method
instead.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide


--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
T

Tony Jollans

Sorry, I kind of assumed that you, as a regular (as far as I can tell from
my short time here) would know this - and it does say so in the referenced
article!

No it's not set by default. You could still use the same method by changing
the code to use late binding:

Sub SendDocumentInMail()

Dim bStarted As Boolean
Dim oOutlookApp As Object 'Outlook.Application
Dim oItem As Object 'Outlook.MailItem

On Error Resume Next

'Get Outlook if it's running
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
'Outlook wasn't running, start it from code
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If

'Create a new mailitem
Set oItem = oOutlookApp.CreateItem(0) ' olMailItem

With oItem
'Set the recipient for the new email
.To = "(e-mail address removed)"
'Set the recipient for a copy
.cc = "(e-mail address removed)"
'Set the subject
.Subject = "New subject"
'The content of the document is used as the body for the email
.Body = ActiveDocument.Content
.Send
End With

If bStarted Then
'If we started Outlook from code, then close it
oOutlookApp.Quit
End If

'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing

End Sub
 

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