Outlook 2007 Macro

G

Guest

I am new to Outlook Macros and Macros in general. I am trying to insert a
word document as text, into the body of a new email message.

I am using Outlook 2007 but it previously worked in Outlook 2003. The
debugger stops on ChangeFileOpenDirectory.

Sub Above_Average_credit()
'
' Macro recorded 6/26/2004 by Garan
'
ChangeFileOpenDirectory "\\Server01\Hawksoft\DOCUMENT\"
Selection.InsertFile FileName:="Above Average Credit.doc", Range:="", _
ConfirmConversions:=False, Link:=False, Attachment:=False
End Sub

I have tried searching this forum and also tried searching the web for
answers to my question with no luck. I know I could manually do what the
macro does but I have many documents with different macros for each one. I
have also tried to record a new macro in Word 2007, to eliminate
compatibilies with a different version of Word, but it spits out the same
macro commands. The macro works in Word 2007 but not Outlook.

What am I missing?
 
S

Sue Mosher [MVP-Outlook]

Your recorded macro was not for Outlook, but for Word. To convert it for use in Outlook VBA, you need to return a Word.Selection object from the mail message that the user current has open. It would look something like this:

Set objDoc = Application.ActiveInspector.WordEditor
Set objSel = objDoc.Windows(1).Selection
objSel.InsertFile <parameters>

If you want to continue using ChangeFileOpenDirectory, you'll need to instantiate a Word.Application object, since that's the object that supports that method, not any Outlook object. To keep in simple, why not concatenate the path with the filename to get the full path?
 
G

Guest

Thank you for the assistance but all this method does is add the document as
an attachment. Is there a way to insert the text of the attachment into the
body of the email message? The same functionality is manualy produced by
clicking on Attach File andselecting the file I want. I then select the drop
down bar, next to the Insert button, and select "Insert as Text".
 
S

Sue Mosher [MVP-Outlook]

All I was trying to do is port your Word macro code to the Outlook environment. That's interesting that InsertFile works differently in the two applications, even with the same objects.

IN any case, what is it that you're really trying to do? If you want to send a Word document as the body of a mail message, the best method is to open the document using Word's Documents.Open method, then use the "Office envelope" feature to turn the document into a message and send it. See http://www.outlookcode.com/codedetail.aspx?id=1333 for a code sample.

Or are you trying to insert some text into an existing email message that already contains text? In what messages using what format(s)?

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
G

Guest

I have many different documents with up to a page of text in them, most have
only a sentence. I want to be able to insert whichever Word doc I need,
directly into the body of the email message, after my cursor.

For example:

Dear Customer,

blah blah my text that I have written in the email message.
(Hit the macro key and select Above_Average_Credit macro. The sentence
within the word document Above Average Credit.doc gets inserted as text after
my cursor).
You qualify with your above average credit score.

Sincerely,

Garan


Using Outlook2003 and Word 2003 the macros worked in Outlook and in Word.
When switching to Outlook 2007 the macros will not work in Outlook but will
work in Word. I know there has to be a different function call such as
"objSel.InsertFileAsText" but that does not work.
 
S

Sue Mosher [MVP-Outlook]

Yes, it's possible, but it's a bit more complicated. You'd need to open the document, get its text, and then insert, using the Selection object that I showed you how to get from an Outlook message. You can probably get most of it done by recording a Word macro. Of course, to make that code run in Outlook, you'd need to instantiate a Word.Application object and use its Documents collection to Open the file, etc.

You might also want to consider using QuickParts, which is the new feature in Office 2007 specifically designed to handle that kind of boilerplate text.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 

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