Consulting

Results 1 to 5 of 5

Thread: CommandBar ID's changed in Outlook 2016

  1. #1

    CommandBar ID's changed in Outlook 2016

    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.
    Last edited by authoriton; 10-30-2017 at 07:35 AM.

  2. #2
    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.
    Attached Images Attached Images

  3. #3
    VBAX Mentor skatonni's Avatar
    Joined
    Jun 2006
    Posts
    347
    Location
    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
    To debug, mouse-click anywhere in the code. Press F8 repeatedly to step through the code. http://www.cpearson.com/excel/DebuggingVBA.aspx

    If your problem has been solved in your thread, mark the thread "Solved" by going to the "Thread Tools" dropdown at the top of the thread. You might also consider rating the thread by going to the "Rate Thread" dropdown.

  4. #4
    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 :-)

  5. #5
    VBAX Mentor skatonni's Avatar
    Joined
    Jun 2006
    Posts
    347
    Location
    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
    To debug, mouse-click anywhere in the code. Press F8 repeatedly to step through the code. http://www.cpearson.com/excel/DebuggingVBA.aspx

    If your problem has been solved in your thread, mark the thread "Solved" by going to the "Thread Tools" dropdown at the top of the thread. You might also consider rating the thread by going to the "Rate Thread" dropdown.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •