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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Office Automation Problem 1

Status
Not open for further replies.

GhostWolf

Programmer
Jun 27, 2003
290
US
I've built a little app that uses Word documents as templates for Outlook e-mail messages. Using the Word document's .Text as the e-mails's .Body, everything was working beautifully, until...

The powers that be decided that our logo should be at the top of the e-mail message, and the font should match the logo's font.

Try as I might, I haven't been able to make this work yet. Is it even possible?

So far I've:[ul]
- added the logo image to the Word document, and used the document's .Range as the message's .Body, (didn't work);

- saved the document as .HTM, and used the HTM document's .Range as the .HTMLBody of the message, (placeholder for the image, and the text was all run together);

- created my own HTML and used it as the .HTMLBody of the message, (same result as with Word's HTM, except that the text maintained it's formatting);

- created Outlook stationery with the logo at the top, and set it as the default stationery for all messages, (no logo, and no placeholder, in the resulting outgoing message).
[/ul]
Any ideas on what to try next will be greatly appreciated.
 
Just out of interest, is the image local or online? Whichever it is, try the other.

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
The image is local, so I'll try the on-line copy when I get back to work this morning...
 
Can you perhaps outline how you program is interacting between Word and Outlook?
 
Why, sure. It's just the usual

Code:
  Set appWord = New Word.Application
  Set docWord = appWord.Documents.Open(TheFileINeedForThisMessage)
  With docWord
    (set some bookmark values)
    tmpStr = docWord.Range.Text
  End With
  docWord.Close
  appWord.Quit
  Set appOutlook = New Outlook.Application
  Set itmOutlook = appOutlook.CreateItem(olMailItem) 
  With itmOutlook
    (set .To, .Subject, .Body)
    .Send
  End With
  Set itmOutlook = Nothing
  Set appOutlook = Nothing

When they requested the image and font, I abandoned tmpstr and .Body in order to try .HTMLBody.

Just a few minutes ago I achieved success with the image via a link to an on-line copy of it, so it looks like I'll have to use .HTMLBody, and write me some HTML versions of these messages now.

If you've got another idea on how I might accomplish this, I'd be more than willing to entertain it.
 
I asked about the image being online because I thought it'd stand more of a chance of working, I think I had a similar issue a while ago with Word; plus of course it'll also work when people receive the email without you having to include the logo as an attachment.

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
>It's just the usual

Why would that be the usual? That's the long way around of doing it in Word, assuming that your version of Word and of Outlook are the same (although not the longest way around, which involves gaining acess to the extended MAPI properties to set up the mail correctly). Here's an alternative approach, in which I've tried to match your example as closely as possible:
Code:
[blue]    Dim appWord As Word.Application
    Dim docWord As Word.Document
    
    Set appWord = New Word.Application
    Set docWord = appWord.Documents.Open(TheFileINeedForThisMessage)
    With docWord
      [green]'(set some bookmark values)[/green]
    End With
    With docWord.MailEnvelope.Item
      [green]'(set .To, .Subject, .Body)
      ' for example:[/green]
      .Recipients.Add "user.name@someaddress.com"
      .Subject = "An Example"
      .Send
    End With
    docWord.Saved = True
    docWord.Close
    appWord.Quit
[/blue]

 
Well, it's usual for me anyhow!

Let me give your code a try. If nothing else, you've just taught me another way of doing it.
 
Well, well. I like that better! It keeps the image that's in the document, along with my formatting, and it looks like I won't need the Outlook reference now.

Good one, strongm.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top