none
Disable Account Button in Outlook 2007 RRS feed

  • Question

  • Hi There,

    I have created a POP account to be used by the users when running a function with access. Now, I don’t want the users to use this email account for regular
    email/msg.

    Does anyone know how to disable the Account button?

    I’ve seen it before but can’t remember.

    Thanks
    SP

    Thanks for everything, all your help is well appreciated

    Wednesday, March 28, 2012 2:19 PM

Answers

  • From what you say the code is running in the Outlook VBA project.
     
    Code in classes in that project won't run unless the class is instantiated, unless the code is in the ThisOutlookSession class module. In any other class you'd need to call some initializer to instantiate and start the class.
     
    In Outlook VBA, Application is always a trusted Outlook.Application object. Application already has been declared (invisibly) as handling events, so no "WithEvents" is needed.
     
    Given that, I'd put this code into the ThisOutlookSession class module as follows:
     
        ' ThisOutlookSession class module
     
        Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
            ' whatever
        End Sub
    Note the Cancel argument.
     
    If you want the code in another class, add the Cancel argument to the signature and make sure to instantiate the class and call the startup initializer method.

    --
    Ken Slovak
    [MVP - Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    Reminder Manager, Extended Reminders, Attachment Options
    http://www.slovaktech.com/products.htm
     
     
    "scorpdevil" <=?utf-8?B?c2NvcnBkZXZpbA==?=> wrote in message news:9e9550f5-5ac5-4331-93cb-711fbb480e9d...

    Hi Ken,

    Sorry for been a bit ignorant about this topic but I’m a little new to Outlook VBA, I mostly work with Access (to me it’s much easier ....lol). What I have done so far it’s straigt forward with error handler or events because I didn’t know how to use the Application_ItemSend or something similar to that.

    I was thinking on doing something like the following: /////>>>>>Class Modules

    Option Explicit
    
    Public WithEvents olApp As Outlook.Application
    Private oAccount As Outlook.Account
    
    Public Sub Application_Startup()
        Set olApp = Outlook.Application
    End Sub
    
    Private Sub olApp_ItemSend(ByVal olItem As Object)
    Select Case olItem.Class
    Case olMailItem
        If Item.Subject Like "Incoming Mail BatchId#" Then
            'DoNothing
        Else
            Set olItem = Application.ActiveInspector.CurrentItem
            Set oAccount = Application.Session.Accounts.Item(1)
            With olItem
                .SendUsingAccount = oAccount
            End With
        End If
    End Select
    End Sub
    

    Please correct me if i'm wrong!!

    Thanks

    SD


    Thanks for everything, all your help is well appreciated


    Ken Slovak MVP - Outlook
    • Marked as answer by scorpdevil Friday, April 6, 2012 6:44 PM
    Thursday, April 5, 2012 6:28 PM
    Moderator
  • Thanks a lot Ken but i came out with the following and work fine + i get the same result.

    Public Sub Application_ItemSend(ByVal olItem As Object, Cancel As Boolean)
    Set olItem = Application.ActiveInspector.CurrentItem
    If olItem.SendUsingAccount = Application.Session.Accounts.Item(2) Then ‘//In my case, my pop index is 2
    	Cancel = True
    	
    	‘//Then you can add whatever here, but basically you have blocked the use of account indexed 2
    
    End If
    End Sub
    

    Thank you very much!

    SD


    Thanks for everything, all your help is well appreciated

    • Marked as answer by scorpdevil Friday, April 6, 2012 6:44 PM
    Friday, April 6, 2012 6:43 PM

All replies

  • You'd need to use ribbon XML to handle and repurpose that menu, if that's possible. The idMso for the menu is "AccountMenu", but I've never seen anything about repurposing menus so I'm not sure if it's possible or not. If it is you'd use a getEnabled callback when that menu is displayed and return False so the menu is disabled. My guess is that it won't work however.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "scorpdevil" <=?utf-8?B?c2NvcnBkZXZpbA==?=> wrote in message news:594cd8a2-f756-413a-9fc6-6f46937bb3f4...
    Hi There,

    I have created a POP account to be used by the users when running a function with access. Now, I don’t want the users to use this email account for regular
    email/msg.

    Does anyone know how to disable the Account button?

    I’ve seen it before but can’t remember.

    Thanks
    SP

    Thanks for everything, all your help is well appreciated


    Ken Slovak MVP - Outlook
    Wednesday, March 28, 2012 2:50 PM
    Moderator
  • Ken,

    Thanks a lot.

    What about using something like this, but I assume this will have to be setup at the onload event of the message form

    • Item.GetInspector.CommandBars("File").FindControl(,3).Visible = False 

           in the Open event of the Custom Form as a possible solution to hide the Save (ID=3 in File CommandBar) button. 

           or 

           Item.GetInspector.CommandBars("Standard").FindControl(, 3).Visible = False 

               in the Open event of the Custom Form as a possible solution to hide the Save (ID=3 in Standard CommandBar) button.



    Thanks for everything, all your help is well appreciated


    • Edited by scorpdevil Wednesday, March 28, 2012 3:17 PM
    Wednesday, March 28, 2012 3:17 PM
  • Hi scorpdevil,

    Thanks for posting in the MSDN Forum.

    Do you mean you want to disable the button under Send/Receive Menu Group?

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Friday, March 30, 2012 6:16 AM
    Moderator
  • Hi Tom,

    Well, when you open a new msg it shows the account button becuase i have more than one email account. I want to find a way to disable or make it not visible. Is that possible?

    Thanks

    SD


    Thanks for everything, all your help is well appreciated

    Wednesday, April 4, 2012 12:02 PM
  • Do you mean dropdown in From field? Maybe you could be content with vba code or add-in that simply sets SendUsingAccount in mailsend event?
    Wednesday, April 4, 2012 12:06 PM
  • Hi Damian,

    That sounds okay with me. Any possible way that i can block the use of the 2nd email account. Any example?


    Thanks for everything, all your help is well appreciated

    Wednesday, April 4, 2012 1:06 PM
  • well, my advice of using SendUsingAccount will not block anything in UI, it will simply dismiss whatever user there selected as a sender and re-set chosen by you account. So that is why i asked if going this route is ok with you, since user will still be able to choose different account and yet plugin will send mails using only one account.
    Wednesday, April 4, 2012 1:10 PM
  • I think that will work....At the end Outlook will correct back to default account.

    Do you have code example that can help?

    Thanks


    Thanks for everything, all your help is well appreciated

    Wednesday, April 4, 2012 1:47 PM
  • Hi Damian,

    I have a question:

    How can I trigger my code when SendItem is executed?

    I've tried the following but no luck: Help!

    Option Explicit

    Private m_Mail As Outlook.MailItem

    Private Sub Application_SendItem(ByVal Item As Object)
    Select Case Item.Class
        Case olMailItem
        If Item.Subject Like "Incoming Mail BatchId#" Then
            'DoNothing
        Else
            Set m_Mail = Application.ActiveInspector.CurrentItem
            With m_Mail
                .SendUsingAccount.Session.Accounts.Item (1)
            End With
        End If
    End Select
    End Sub

    Thanks

    SP


    Thanks for everything, all your help is well appreciated


    • Edited by scorpdevil Wednesday, April 4, 2012 6:59 PM
    Wednesday, April 4, 2012 6:58 PM
  • your line

    With m_Mail
                .SendUsingAccount.Session.Accounts.Item (1)
            End With

    is wrong - you have to set recipient there, something like:

    Set properRecipient = Application.Session.Accounts.Item(1)

    m_Mail.SendUingAccount = properRecipient

    Thursday, April 5, 2012 6:10 AM
  • Hi Damian,

    I've made proper changes but still not triggering when I click the Send button. I think I'm using the wrong application command:

    Private Sub Application_SendItem(ByVal olItem As Object)
    Select Case olItem.Class
        Case olMailItem
        If Item.Subject Like "Incoming Mail BatchId#" Then
            'DoNothing
        Else
            Dim oAccount As Outlook.Account
            Set olItem = Application.ActiveInspector.CurrentItem
            Set oAccount = Application.Session.Accounts.Item(1)
            With olItem
                .SendUsingAccount = oAccount
            End With
        End If
    End Select
    End Sub

    Thanks

    SD


    Thanks for everything, all your help is well appreciated

    Thursday, April 5, 2012 12:40 PM
  • The actual event has this signature:
     
    Private Sub Application_ItemSend(ByVal olItem As Object)
    Does it work using that signature?

    --
    Ken Slovak
    [MVP - Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    Reminder Manager, Extended Reminders, Attachment Options
    http://www.slovaktech.com/products.htm
     
     
    "scorpdevil" <=?utf-8?B?c2NvcnBkZXZpbA==?=> wrote in message news:97128a88-175f-49f9-b8e1-ad9dfa1d5bc0...

    Hi Damian,

    I've made proper changes but still not triggering when I click the Send button. I think I'm using the wrong application command:

    Private Sub Application_SendItem(ByVal olItem As Object)
    Select Case olItem.Class
        Case olMailItem
        If Item.Subject Like "Incoming Mail BatchId#" Then
            'DoNothing
        Else
            Dim oAccount As Outlook.Account
            Set olItem = Application.ActiveInspector.CurrentItem
            Set oAccount = Application.Session.Accounts.Item(1)
            With olItem
                .SendUsingAccount = oAccount
            End With
        End If
    End Select
    End Sub

    Thanks

    SD


    Thanks for everything, all your help is well appreciated


    Ken Slovak MVP - Outlook
    Thursday, April 5, 2012 4:08 PM
    Moderator
  • The actual event has this signature:
    Private Sub Application_ItemSend(ByVal olItem As Object)
    Does it work using that signature?

    --
    Ken Slovak
    [MVP - Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    Reminder Manager, Extended Reminders, Attachment Options
    http://www.slovaktech.com/products.htm
    "scorpdevil" <=?utf-8?B?c2NvcnBkZXZpbA==?=> wrote in message news:97128a88-175f-49f9-b8e1-ad9dfa1d5bc0...

    Hi Damian,

    I've made proper changes but still not triggering when I click the Send button. I think I'm using the wrong application command:

    Private Sub Application_SendItem(ByVal olItem As Object)
    Select Case olItem.Class
        Case olMailItem
        If Item.Subject Like "Incoming Mail BatchId#" Then
            'DoNothing
        Else
            Dim oAccount As Outlook.Account
            Set olItem = Application.ActiveInspector.CurrentItem
            Set oAccount = Application.Session.Accounts.Item(1)
            With olItem
                .SendUsingAccount = oAccount
            End With
        End If
    End Select
    End Sub

    Thanks

    SD


    Thanks for everything, all your help is well appreciated


    Ken Slovak MVP - Outlook

    Sorry - I used the wrong terminology, I was referring to that. It's not triggering the code. Should the signature be in a different way?

    Thanks

    SD


    Thanks for everything, all your help is well appreciated

    Thursday, April 5, 2012 5:40 PM
  • You had been referring to Application_SendItem(). There is no such event. There is an Application_ItemSend() event.
     
    Are you actually setting up the correct event handler? How are you setting it up?
     
    Does the event get called?

    --
    Ken Slovak
    [MVP - Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    Reminder Manager, Extended Reminders, Attachment Options
    http://www.slovaktech.com/products.htm
     
     
    "scorpdevil" <=?utf-8?B?c2NvcnBkZXZpbA==?=> wrote in message news:65085b4d-1d25-482d-9fa7-99e032984f74...
     

    Sorry - I used the wrong terminology, I was referring to that. It's not triggering the code. Should the signature be in a different way?

    Thanks

    SD


    Thanks for everything, all your help is well appreciated


    Ken Slovak MVP - Outlook
    Thursday, April 5, 2012 5:48 PM
    Moderator
  • Hi Ken,

    Sorry for been a bit ignorant about this topic but I’m a little new to Outlook VBA, I mostly work with Access (to me it’s much easier ...lol). What I have done so far it’s straigt forward with error handler or events because I didn’t know how to use the Application_ItemSend or something similar to that.

    I was thinking on doing something like the following: /////>>>>>Class Modules

    Option Explicit
    
    Public WithEvents olApp As Outlook.Application
    Private oAccount As Outlook.Account
    
    Public Sub Application_Startup()
        Set olApp = Outlook.Application
    End Sub
    
    Private Sub olApp_ItemSend(ByVal olItem As Object)
    Select Case olItem.Class
    Case olMailItem
        If Item.Subject Like "Incoming Mail BatchId#" Then
            'DoNothing
        Else
            Set olItem = Application.ActiveInspector.CurrentItem
            Set oAccount = Application.Session.Accounts.Item(1)
            With olItem
                .SendUsingAccount = oAccount
            End With
        End If
    End Select
    End Sub
    

    Please correct me if i'm wrong!!

    Thanks

    SD


    Thanks for everything, all your help is well appreciated

    Thursday, April 5, 2012 6:11 PM
  • From what you say the code is running in the Outlook VBA project.
     
    Code in classes in that project won't run unless the class is instantiated, unless the code is in the ThisOutlookSession class module. In any other class you'd need to call some initializer to instantiate and start the class.
     
    In Outlook VBA, Application is always a trusted Outlook.Application object. Application already has been declared (invisibly) as handling events, so no "WithEvents" is needed.
     
    Given that, I'd put this code into the ThisOutlookSession class module as follows:
     
        ' ThisOutlookSession class module
     
        Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
            ' whatever
        End Sub
    Note the Cancel argument.
     
    If you want the code in another class, add the Cancel argument to the signature and make sure to instantiate the class and call the startup initializer method.

    --
    Ken Slovak
    [MVP - Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    Reminder Manager, Extended Reminders, Attachment Options
    http://www.slovaktech.com/products.htm
     
     
    "scorpdevil" <=?utf-8?B?c2NvcnBkZXZpbA==?=> wrote in message news:9e9550f5-5ac5-4331-93cb-711fbb480e9d...

    Hi Ken,

    Sorry for been a bit ignorant about this topic but I’m a little new to Outlook VBA, I mostly work with Access (to me it’s much easier ....lol). What I have done so far it’s straigt forward with error handler or events because I didn’t know how to use the Application_ItemSend or something similar to that.

    I was thinking on doing something like the following: /////>>>>>Class Modules

    Option Explicit
    
    Public WithEvents olApp As Outlook.Application
    Private oAccount As Outlook.Account
    
    Public Sub Application_Startup()
        Set olApp = Outlook.Application
    End Sub
    
    Private Sub olApp_ItemSend(ByVal olItem As Object)
    Select Case olItem.Class
    Case olMailItem
        If Item.Subject Like "Incoming Mail BatchId#" Then
            'DoNothing
        Else
            Set olItem = Application.ActiveInspector.CurrentItem
            Set oAccount = Application.Session.Accounts.Item(1)
            With olItem
                .SendUsingAccount = oAccount
            End With
        End If
    End Select
    End Sub
    

    Please correct me if i'm wrong!!

    Thanks

    SD


    Thanks for everything, all your help is well appreciated


    Ken Slovak MVP - Outlook
    • Marked as answer by scorpdevil Friday, April 6, 2012 6:44 PM
    Thursday, April 5, 2012 6:28 PM
    Moderator
  • Thanks a lot Ken but i came out with the following and work fine + i get the same result.

    Public Sub Application_ItemSend(ByVal olItem As Object, Cancel As Boolean)
    Set olItem = Application.ActiveInspector.CurrentItem
    If olItem.SendUsingAccount = Application.Session.Accounts.Item(2) Then ‘//In my case, my pop index is 2
    	Cancel = True
    	
    	‘//Then you can add whatever here, but basically you have blocked the use of account indexed 2
    
    End If
    End Sub
    

    Thank you very much!

    SD


    Thanks for everything, all your help is well appreciated

    • Marked as answer by scorpdevil Friday, April 6, 2012 6:44 PM
    Friday, April 6, 2012 6:43 PM