word to outlook

D

darren

Hi
i would like to know how to send from word to outlook an
activedocument (without saving) as attachment with VBA.
i've also to input : body, object,sentonbehalfofname

thanks
Darren

PS:below u can find a code but it's incomplete (no
attachment selected

Sub email()
Set myOutlook = CreateObject("Outlook.Application")
Set mymail = myOutlook.CreateItem(olMailItem)
mymail.Subject = "Fac simile"
mymail.sentonbehalfofname = " "
mymail.Body = ""
mymail.Display
End Sub
 
H

Helmut Weber

Hi Darren,
mymail.attachments.Add ActiveDocument.FullName
however, according to my knowledge, if it is that,
you are talking about, a new document,
which was never saved, isn't really existing, it has
no location. (activedocument.path = "").
Saving is essential, probably. What's wrong with saving,
attaching, sending, closing and killing the doc?
And, what good would it be for, not to record, what was sended?

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
 
D

Darren

Hi Helmut,

thanks for all suggestions:
*With first string i've a run time error '438'
*I also think that saving is essential.Nothing it's wrong
in your words but i can't access to the folder in which
the doc is saved.Probably anther solution, as you said, is:

-save the doc (to a temp folder)
-attach
-delete it

what do you thik about it?
do you have a part of this code?

thanks
Darren
 
D

Dave Neve

Hi

I'm hopeless on VBA but I do know a bit about Outlook.

I regularly send docs from Word as attachments just by using the Outlook
Icone which does this.

I don't save the .doc in Word cos it is saved in Outlook.

It appears as doc.1(attachment) in Outlook.

Why not run VB on the doc, do what you want and then use the Outlook icone?

Hope this helps a little bit and that I haven't got hold of the wrong end of
the stick.
 
S

Steve Lang

Hi Darren,

here is some code I use to automate e-mails from Word:

Create a reference to the Outlook object model and add some code of this
nature (I use variables for the To, Subject, etc, but you can hardcode a
string in there as well):

Set myOutlook = CreateObject("Outlook.Application")
Set myNameSpace = myOutlook.GetNamespace("MAPI")
Set myItem = myOutlook.CreateItem(olMailItem)
With myItem
.To = strTo 'this would be youre-mail address
.Subject = strDocName 'the subject
.Body = strMsg 'whatever you want it to be
.Attachments.Add strDocPath & strDocName 'the full name and path
to the document
.Send
End With
Set myOutlook = Nothing
Set myNameSpace = Nothing
Set myItem = Nothing

HTH and have a great day!

Steve Lang
 
H

Helmut Weber

Hi Darren,
how about this:
Dim sDcm As String ' path + name of doc
Set myOutlook = CreateObject("Outlook.Application")
Set mymail = myOutlook.CreateItem(olMailItem)
ActiveDocument.SaveAs "c:\test\test.doc"
mymail.Subject = "Fac simile"
mymail.sentonbehalfofname = " "
mymail.Body = "" ' not necessary
sDcm = ActiveDocument.FullName
mymail.attachments.Add sDcm
mymail.Display ' or send of course
ActiveDocument.Close
Kill sDcm '!
Set myOutlook = Nothing '!
Set mymail = Nothing '!

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
 
H

Helmut Weber

Hi Darren,
in detail, this seems to be more complicated as I've thought.
I've just discovered, that there is now a "test.doc"
in "C:\WINDOWS\Temporary Internet Files\OLK31A2"
Do you have to take care of this file, too?
Or just forget about it?
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
 
D

Darren

Helmut and Steve,

thanks for suggestions and codes.I'll try both solution
and certainly let you know the result.
Helmut I save not as test.doc

Darren
 

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