Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

word doc as body of mail

Status
Not open for further replies.

kermit01de

Technical User
Jan 20, 2002
256
0
0
DE
Hi,

Original issue:
list of recipients should receive mail with pdf attached.

I already found a solution for that in general, but as I do not have any clue about vba, maybe someone could help out at the missing point.

I have an Excel table containing the recipients(A), Subject(B), Text(C) and in F2-F10 up to ten attachments. Then I have a word doc (P:\MyMailBody.doc) that should be sent as the body of the mail. (eg. containing something like: Dear friends, please find attached etc etc etc Kind regards)

How should I change the code at this point

Code:
.Body = Cells(i, 3) 'Sendtext"

to have the content of the doc in the body?

Thanks for any hint



Kind regards
Mirko
--------------------------------------
>>>>>> ... I am sure, some supportissues are a matter of PEBKAC ... <<<<<
 
Include this in your declarations:
Code:
Dim wdApp as Word.Application
Dim wdDoc as Word.Document

And this in your code in place of what you have:
Code:
Set wdDoc = wdApp.Documents.Open(MyDoc)
wdDoc.Select
olMessage.Body = wdDoc.ActiveWindow.Selection
wdApp.quit
Set wdApp = Nothing
Set wdDoc = Nothing

And your MyDoc text will be the body of your e-mail -- of course some formatting will be lost going from .doc to .rtf

Good luck.
 
You could aslo use the WordEditor function of the email itself...

Assuming that the message is displayed:
olMessage.GetInspector.WordEditor.Range(start:=0, End:=0) = wdDoc.ActiveWindow.Selection

or you may have to copy the data from the .doc first
wdDoc.Select
wdDoc.Copy
olMessage.GetInspector.WordEditor.Range(start:=0, End:=0).Paste

I'm not that familiar with interaction with Word... more with Excel to Outlook.




OCD, it’s not obsessive if you can control it…
 

I just noticed that I failed to include the New keyword to dimension the word application like:
Code:
Dim wdApp as New Word.Application
so that the application is automatically opened when referenced.

Alternately you could insert:
Code:
Set wdApp = Word.Application
before the line:
Code:
Set wdDoc = wdApp.Documents.Open(MyDoc)
and achieve the same results.

@ yooneek:

What would be the benefit of using WordEditor? I have never used it before. Does it provide more flexibility? If not, that method just uses more code to perform the same function.
 
Thanks for the hints, I will try that on Monday when I am back in the office and come back here...

Have a nice weekend



Kind regards
Mirko
--------------------------------------
>>>>>> ... I am sure, some supportissues are a matter of PEBKAC ... <<<<<
 
Outlook's base for the Body is a Word document. When calling it from inside Outlook VBA, .GetInspector calls the Item and allows for you to manipulate the Body using .WordEditor (Word VBA) rather than flipping between Word/Outlook code.

Comes in handy when you just need to do a one line entry.




OCD, it’s not obsessive if you can control it…
 
@Gammachaser
What I get with your suggestion is on line(s)

Dim wdApp as Word.Application --- (same with "New")
Dim wdDoc as Word.Document

the error message

Compilation Error
"User defined type not defined"

What is wrong with me?

@yooneek
I am not quite clear where to assign the source doc for copying the text from. Or will it be copied from a mail draft?

Thank you - hopefully you can kick me in the right direction to fix the error.

Kind regards
Mirko
--------------------------------------
>>>>>> ... I am sure, some supportissues are a matter of PEBKAC ... <<<<<
 
Ok, what I did is the following:

Code:
Dim wdApp As Object
Dim wdDoc As Object

and later on

Code:
Set wdApp = CreateObject("Word.Application")
Set wdDoc = wdApp.Documents.Open(BdyTxt)
            wdDoc.Select
                .Body = wdDoc.ActiveWindow.Selection
            wdApp.Quit
Set wdApp = Nothing
Set wdDoc = Nothing

That works great - thanks for all of your help.

Kind regards
Mirko
--------------------------------------
>>>>>> ... I am sure, some supportissues are a matter of PEBKAC ... <<<<<
 
The reason the second method works and not the first can be found in the References List.

In the VB Window (not the database window) Click on Tools and select References. You will get a list of installed .dlls that you can include in your project. Go down the list and select Microsoft Word (xx.x) Object Library (the xx.x will be the version level you have on your computer) and check the box next to it and click OK. That will make the library containing Word variables (very helpful) and objects (with all of their properties and methods) available in Access. You can do the same if you want to automate Outlook, Excel, or other Apps. It even gives you the 'autocomplete' functions where you get dropdown lists of available commands and are prompted for variables.

I am glad you got it working with the generic 'Object' but try this method and I think you will find things much easier in the future.
 
you will find things much easier in the future
Unless the access app is used in an heterogenous office environment ...
 
Thanks again for all hints!

This will be used on one PC only in the "General BackOffice" to send a pdf-Info as attachment to several recipients from time to time.

btw. It's Excel as mentioned in the initial post.

Kind regards
Mirko
--------------------------------------
>>>>>> ... I am sure, some supportissues are a matter of PEBKAC ... <<<<<
 
Works the same way in Excel. Make sure you are in a code window and click Tools, References...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top