none
Can be a mix of a Control created in VS project and button, which has been associated wit macro, created in Outlook in same group of ribbon? RRS feed

  • Question

  • Hello,

    I have a Button, which has been associated wit macro, in "Customize Ribbon" dialog window in Outlook. That Button is below a group called LHO. I want to add a control in Visual Studio. Can I put this control in the same group LHO in some way? Or can I move the Button, which has been associated wit macro, to a group, which has made in Visual Studio?

    B.R.

    Majid

    Saturday, May 19, 2018 5:40 AM

All replies

  • Hi majid_fkh,

    I suggest you to create both button using VSTO.

    Then try to call the VBA code on the click event of that button.

    Example code:

      Private Sub p_Call_VBA(p_Procedure As String)
            Dim mObj_of_CommandBars As Microsoft.Office.Core.CommandBars, mObj_ou_Explorer As Outlook.Explorer, mObj_ou_MailItem As Outlook.MailItem, mObj_ou_UserProperty As Outlook.UserProperty
    
            mObj_ou_Explorer = Globals.Menu_AddIn.Application.ActiveExplorer
            'I want this to run only when one item is selected
            If mObj_ou_Explorer.Selection.Count = 1 Then
                mObj_ou_MailItem = mObj_ou_Explorer.Selection(1)
                mObj_ou_UserProperty = mObj_ou_MailItem.UserProperties.Add("COM AddIn-Azimuth", Outlook.OlUserPropertyType.olText)
                mObj_ou_UserProperty.Value = p_Procedure
                mObj_of_CommandBars = mObj_ou_Explorer.CommandBars
                'Call the clipboard event Copy
                mObj_of_CommandBars.ExecuteMso("Copy")
            End If
        End Sub

    For full code, You can refer link below.

    Call Outlook VBA sub from VSTO

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, May 21, 2018 9:32 AM
    Moderator
  • Hello Deepak,

    Thanks for your reply!

    The new control made in VSTO solution shall run C# code. Can I call the VBA code on the click event of that button? I mean can I have mix of C# and VBA code in same solution?

    B.R.

    Wednesday, May 23, 2018 4:56 AM
  • Hi majid_fkh,

    You had asked,"Can I call the VBA code on the click event of that button? I mean can I have mix of C# and VBA code in same solution?"

    You can have a mix of C# and VBA code but you need to put your VBA code on each machine you install your VSTO Add in.

    In other applications like Word, Excel. You can call the VBA code by just using line below.

    Application.Run("Your sub name")

    In Outlook, Run method is not available. So as a work around you can refer example code in the link that I shared with you in my previous reply.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, May 23, 2018 6:10 AM
    Moderator
  • Hello Deepak,

    Thanks for your reply. I tried to understand the solution in the link you suggested. It is complex to me to understand it. I want just to call an existing VBA procedure from btnClick for a control in a ribbon in VSTO C# solution.

    B.R.

    Thursday, May 24, 2018 7:29 AM
  • Hello,

    You can't create a custom ribbon UI in the built-in tab. Read more about the Fluent UI (aka Ribbon UI) in the following series of articles:

    Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3)

    Customizing the 2007 Office Fluent Ribbon for Developers (Part 2 of 3)

    Customizing the 2007 Office Fluent Ribbon for Developers (Part 3 of 3)

    Instead, you can try to add a button associated with a macro to a custom group manually. 


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Monday, May 28, 2018 12:34 AM