Macros working in office 2003 fail in 2007

L

Lorne

I have 2 html templates I use for sending mail in outlook. They execute
from macro buttons I added to the menu, and work fine in office 2003. I
just upgraded to office 2007 and the macros not longer work correctly - they
load the text part of stationery and set the sending account but do not
display the page backround image or a jpg embeeded in the page. I get an
error message saying file not found, it must have been moved or deleted but
both jpg's are in the correct folder.

If I open the stationery via the actions menu - send mail using... then both
mail templates appear correctly.

If I open the html file in IE they both display correctly.

The relevant files are all in the folder C:\Program Files\Common
Files\Microsoft Shared\Stationery.

Any idea why the code below is failing?

Code:
***************************
Dim NewMail As Outlook.MailItem
Dim objFS, objStationeryFile

Sub NewLetter2()
Const strStationeryFile = "C:\Program Files\Common Files\Microsoft
Shared\Stationery\Letter2.htm"
Set NewMail = Application.CreateItem(olMailItem)
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objStationeryFile = objFS.OpenTextFile(strStationeryFile, 1, False)
NewMail.HTMLBody = objStationeryFile.ReadAll
objStationeryFile.Close
NewMail.Display
End Sub

Sub NewICC()
Const strStationeryFile = "C:\Program Files\Common Files\Microsoft
Shared\Stationery\ICC.htm"
Set NewMail = Application.CreateItem(olMailItem)
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objStationeryFile = objFS.OpenTextFile(strStationeryFile, 1, False)
NewMail.HTMLBody = objStationeryFile.ReadAll
objStationeryFile.Close
NewMail.Display
MyStr = Set_Account("ICC", NewMail)
End Sub

Function Set_Account(ByVal AccountName As String, M As Outlook.MailItem) As
String
Dim OLI As Outlook.Inspector
Dim strAccountBtnName As String
Dim intLoc As Integer
Const ID_ACCOUNTS = 31224

Dim CBs As Office.CommandBars
Dim CBP As Office.CommandBarPopup
Dim MC As Office.CommandBarControl

Set OLI = M.GetInspector
If Not OLI Is Nothing Then
Set CBs = OLI.CommandBars
Set CBP = CBs.FindControl(, ID_ACCOUNTS)
If Not CBP Is Nothing Then
For Each MC In CBP.Controls
intLoc = InStr(MC.Caption, " ")
If intLoc > 0 Then
strAccountBtnName = Mid(MC.Caption, intLoc + 1)
Else
strAccountBtnName = MC.Caption
End If
If strAccountBtnName = AccountName Then
MC.Execute
Set_Account = AccountName
GoTo Exit_Function
End If
Next
End If
End If
Set_Account = ""

Exit_Function:
Set MC = Nothing
Set CBP = Nothing
Set CBs = Nothing
Set OLI = Nothing
End Function
 
L

Lorne

Lorne said:
I have 2 html templates I use for sending mail in outlook. They execute
from macro buttons I added to the menu, and work fine in office 2003. I
just upgraded to office 2007 and the macros not longer work correctly -
they load the text part of stationery and set the sending account but do
not display the page backround image or a jpg embeeded in the page. I get
an error message saying file not found, it must have been moved or deleted
but both jpg's are in the correct folder.

It seems to work if I put fully qualified file paths instead of the file
names for the jpg files. Anybody know if there is a command to set the
common files stationery path as the working directory?

Changing the file names is a bit annoying as FrontPage does not let you do
it - if the picture file is in the same folder and you press file-save it
auto deletes the path which is being too clever given that other parts of
office do not seem to know that the file is in the same folder and can't
find it.
 
R

Roady [MVP]

It will probably not solve your issue but it is really not recommended to
mess with files in the Program Files directory. If you have custom
stationery I recommend you put that in the Stationery folder of the All
Users directory.

Putting fully qualified paths in a HTML template may work on the computer
you are testing on but it probably won't work on the receiving end where the
jpg-files are not in the same folders. Relative paths is still what you
need.

Does the stationery work correctly when you use it manually instead of via
code?
 
L

Lorne

Yes the stationery does work if I open it using the menu "actions-new
message using".

The only reason I have these files in the common file folder is because that
is where outlook used to keep its stationery when I first wrote them, which
was for office 98 I think. I can easily move them to all users stationery
but I was more concerned with why outlook does not find the jpg pictures
when they are in the same folder as the html file.

Lorne
 
R

Roady [MVP]

If it works manually there must be something in which it gets called
programmatically. It's better to repost this in a developers newsgroup down
the hall. outlook.program_vba probably will do.
 

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