After Office 2007 SP2 install - Outlook 2007 macro no longer worki

  • Thread starter Thread starter rpratikno
  • Start date Start date
R

rpratikno

Hi guys,

I have a macro that will move all email sent with "sendonbehalf" properties
to the group mailbox. I found it on someone post and it has been working like
a charm until I installed Office SP2. It doesn't work anymore. Do anyone
might know what is the issue? I have try re-install Office then also SP2 with
no joy.

Below is the code
Private SentEntryID As String
Private SentStoreID As String
Private WithEvents objSentItems As Items
Private MailItem As Outlook.MailItem

Public Sub Application_Startup()
'Retrieve ID for accessing non-default sent folder
getStoreFolderID ("Mailbox - group")
Set objSentItems =
Application.Session.GetDefaultFolder(olFolderSentMail).Items
End Sub

Function getStoreFolderID(StoreName)
'Gets the Shared Account Sent Folder
Dim Store As Object
Dim StoreFolder As Object
Dim i As Integer
Set Store = Application.GetNamespace("mapi").Folders
For Each StoreFolder In Store
If StoreFolder.Name = StoreName Then
For i = 1 To StoreFolder.Folders.Count
If StoreFolder.Folders(i).Name = "Sent Items" Then
SentEntryID = StoreFolder.Folders(i).EntryID
SentStoreID = StoreFolder.Folders(i).StoreID
Exit For
End If
Next
Exit For
End If
Next
Set Store = Nothing
Set StoreFolder = Nothing
End Function

Private Sub objSentItems_ItemAdd(ByVal Item As Object)
'Fired when something is added to personal "Sent Mail" folder
If TypeOf Item Is Outlook.MailItem Then
With Item
Set MailItem = Application.GetNamespace("mapi").GetItemFromID(.EntryID,
..Parent.StoreID)
End With
If MailItem.SentOnBehalfOfName = "group" Then
Set DestinationFolder = Application.Session.GetFolderFromID(SentEntryID,
SentStoreID)
MailItem.Move (DestinationFolder)
End If
End If
Set MailItem = Nothing
End Sub

Any suggestion or thinking are welcomed.

Thanks.
 
Doesn't work in what way? Does the code run at all? What if you run it
manually, do you get any errors? Which line or lines throw errors?
 
Hi Ken,

Thanks for replying.

It no longer move sent email automatically to "group" mailbox, the sent
email is sitting on individual users mailbox.

If I run it manually it didn't throw any error message at all.

Thank you.
 
What I'd do in that case is to put some Debug.Print statements in the code
in the startup initializer and the code that's supposed to be called and see
where the statements fail to write to the Immediate window and the code is
failing. I'd also set up breakpoints in the getStoreFolderID() and
objSentItems_ItemAdd() methods and send some test messages that should
trigger your code and see what happens. That's about the only way to figure
out what's going on.
 
Hi Ken,

Thanks for the tips to start debugging =) I manage to found the cause.

After installing Outlook SP2, if we reply any group email on group mailbox,
the email From field will no longer contain SendOnBehalf properties, which
definitely break the macro.

Do you have any suggestion to fix it?

Thanks.
 
I'm sorry, I can't reproduce that at all.

I tested with Outlook 2007 SP2 and any reply from a shared mailbox using the
From as the shared mailbox alias always provided SentOnBehalfOfName and the
equivalent MAPI property in the items going to Sent Items in the default
mailbox.

Original emails using that From also had that property on them.
 
Ken, just curious: If you reply from the mailbox, is the From field in the
UI already filled in with the mailbox name? Or does the user have to fill it
in manually?

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
In replying from the mailbox the From is already filled in with the mailbox
SMTP address.
 
Hi Ken,

Thanks for trying to reproduce my scenario, I appreciate that. Could you
please define which one is default mailbox? I assume default mailbox is the
sender mailbox, not the shared mailbox. Please correct me if I'm wrong.

The goal of this macro is to automatically move all email that a user reply
from shared mailbox into shared mailbox's sent items, not to the user
sender/default sent items.

I used Macro "watch" to see string value on the MailItem property. When I
hit reply on shared mailbox's email, the MailItem's SharedOnBehalfOfName
property string value is the user's name instead of the shared mailbox's name.

I did check what the recipient see on their side, the email From field is
"user on behalf of shared". On sender side (me) the email From field is only
"user" without "on behalf of shared". So I'm positive the issue is on Outlook
instead of Exchange server. I got 10 users having the same issue here.

Could you please assist me more further? Your help is much appreciated.
 
The default mailbox is wherever the emails are delivered for that Outlook
profile. It would be the mailbox for that Exchange alias.

What shows up in From would depend on which alias is answering that email
and what permissions they have on the shared mailbox. You can have send on
behalf of permissions, which shows one thing in From. You can have
SendAs/ReceiveAs permissions, which allow you to send as if you were that
mailbox alias. For example, if I answer an email from my Sales mailbox the
answer goes out from Sales since I gave myself SendAs/ReceiveAs permissions
on that mailbox, even though I'm logged into my own mailbox.
 
Hi Ken,

Thanks for replying.

I do understand your explanation are what the Exchange features and default.
When you reply email on Sales mailbox, the email that you sent will go to the
profile sent items, which is not what our organisation want. That is the
reason I use the macro, we want the sent email of replying Sales mailbox not
to the profile's Sent Items, yet to the Sales mailbox's sent items.

What I found is on Outlook side (not Exchange), with Outlook SP2, the
SendOnBehalfOfName property is no longer contain the Sales' name. It is now
contain profile's name. This is not happening before Outlook SP2, I'm
wondering if this is a bug on Office SP2? I didn't make any changes on the
macro code. The exactly same macro works fine prior to Office SP2.

However, at the reply email receiver the sender name is correct, which is
"profile on behalf of sales". So I'm sure this is not the problem of Exchange
configuration.

Will you be able to confirm that this is a bug on Office SP2? Please do
correct me if I'm wrong.

Thank you very much for your thinking, it is much appreciated.
 
I told you already that I tested this on Outlook 2007 SP2 and did not find
what you are finding. So it is not a bug in Outlook 2007 SP2. Why you see
the results you see I have no idea, but if it was a bug in the service pack
I'd see it here also on the 2 computers I tested on.
 
rpratikno said:
Hi Ken,

Thanks for trying to reproduce my scenario, I appreciate that. Could you
please define which one is default mailbox? I assume default mailbox is the
sender mailbox, not the shared mailbox. Please correct me if I'm wrong.

The goal of this macro is to automatically move all email that a user reply
from shared mailbox into shared mailbox's sent items, not to the user
sender/default sent items.

I used Macro "watch" to see string value on the MailItem property. When I
hit reply on shared mailbox's email, the MailItem's SharedOnBehalfOfName
property string value is the user's name instead of the shared mailbox's name.

I did check what the recipient see on their side, the email From field is
"user on behalf of shared". On sender side (me) the email From field is only
"user" without "on behalf of shared". So I'm positive the issue is on Outlook
instead of Exchange server. I got 10 users having the same issue here.

Could you please assist me more further? Your help is much appreciated.
 
Apologies if I have hijacked this post, but I think I have encountered a
similar issue with some Outlook 2007 vba after upgrading to SP2. The original
code was like this:

Set myOlApp1 = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp1.GetNamespace("MAPI")

Set myTasks = myNameSpace.GetDefaultFolder(olFolderTasks).Items
Set myitems = myTasks.Restrict("[Categories] = XYZ Category")

For Each myItem In myItems
If (myItem.Class = olTask) Then
myItem.Delete
End If
Next

Set myitems = Nothing

After SP2, this code would prematurely break out of the For Each ... Next
loop without deleting all the Task items in the collection.

After debugging and trying to delete the items by referring directly to
their index in the collection, I think I found where the issue is eg:

i = 1
For c = 1 To myItems.Count
If (myitems(i).Class = olTask) Then
myitems(i).Delete
Else
i = i + 1
End If
Next

The problem here is that regardless of the index of the item you attempt to
delete, while it physically deletes the correct item, it deletes the last
item in the myItems collection. Now this code may not have worked correctly
anyway, but debugging through it highlights the disconnect as the myItems
collection becomes out of synch with reality.

I suspect the issue is the same under both examples; both code examples
exhibit the same result regarding which Task items get deleted, and which
remain.

I'd be interested to see if this can be recreated elsewhere under Outlook
2007 SP2. Strangely enough, the .Remove method works fine:

If (myitems(i).Class = olTask) Then
myitems.Remove (i)
Else
i = i + 1
End If


Cheers,


Bruce
 
Hi bfoxall, I assume we both wondering how Office SP2 break our macro. I'm
not sure is this some kind of bug that we can forward to Microsoft Support.

With my macro, I don't know any work around of the miss behaving mail items
property value. Do you have any suggestion?
 
I have the same problem.
I don't use your macro but a com plugin UniSent (same issue)
If you start a mail from scratch the problem doesn't exist
If you <clear FromField> + <Retype what was there> the problem doesn't exist
(Actually its enough to just hit <enter> in the AutoPoppulated FromField).
Big problem hope someone can solve it.

:) Morten
 
Back
Top