PDA

View Full Version : CommandBar ID's changed in Outlook 2016



authoriton
10-30-2017, 07:16 AM
Hi All,

First post to the forum and i would really appreciate some help with this issue.

My company has recently migrated be from Outlook 2010 to Outlook 2016. In 2010, i had a macro embedded in the Application_ItemSend event that changed the value of the 'From' field automatically from whatever it was set to, to my personal account.

To do this, I used control ID 31224 and modified the 'Caption' with:


Private Sub Application_ItemSend(ByVal item As Object, Cancel As Boolean)
oAccount = Application.Session.Accounts.item(1).UserName
Call set_account(item,oAccount)
End Sub

Function Set_Account(M,AccountName)
Set OLI = M.GetInspector
Set CBs = OLI.CommandBars
Set CBP = CBs.FindControl(, 31224)
For Each MC In CBP.Controls
intLoc = InStr(MC.Caption, " ") strAccountBtnName = MC.Caption
If strAccountBtnName <> AccountName Then
MC.Execute
Set_Account = AccountName
GoTo Exit_Function
End If
Next
Exit_Function:
End Function

However, Office 2016 doesn't seem to have Control ID 31224. Any idea how I can change the account I am sending the email 'From' using a VBA macro in Outlook 2016?

I have checked through all the CommandBars and I cant find an alternative option.

authoriton
11-03-2017, 09:15 AM
Lots of views and no help :-(
Its really stumping me too!

Perhaps the question is too specific. If anyone has any idea how I can interact with the 'From' field via VBA (other than via the CommandBars) in Outlook 2016 that would work too.

skatonni
11-15-2017, 11:59 AM
This should change the "from" to the first account. If your set up does not do this automatically perhaps you need the second option.


Private Sub Application_ItemSend(ByVal item As Object, Cancel As Boolean)

' option 1
item.SentOnBehalfOfName = Session.GetDefaultFolder(olFolderInbox).Parent

' option 2
' item.SentOnBehalfOfName = meATSIGNsomewhere.com

End Sub

authoriton
11-30-2017, 01:27 AM
The SentOnBehalfOfName property indicates whether an email has previously been sent on behalf of someone else. On a new email this property is blank. It does not have any effect on the account that will send the email.

Thanks for the suggestion though. All suggestions welcome :-)

skatonni
11-30-2017, 10:32 AM
See if SendUsingAccount does what you want.


Private Sub Which_Account()

Dim i As Long

For i = 1 To Session.Accounts.count
Debug.Print "Account # " & i & ": " & Session.Accounts.Item(i)
Next i
End Sub

Private Sub SendUsingAccount_Sample()
Dim objMailItem As mailItem
Dim AccountName As String
AccountName = "Found with Which_Account"
Set objMailItem = CreateItem(olMailItem)
With objMailItem
On Error GoTo notAvailable
.SendUsingAccount = Session.Accounts(AccountName)
'or index
'.SendUsingAccount = Session.Accounts.Item(2)
.Display ' or .Send
End With
ExitRoutine:
Set objMailItem = Nothing
Exit Sub

notAvailable:
MsgBox "Verify " & AccountName
End Sub