locked
Import VBA module for Outlook using Powershell RRS feed

  • Question

  • Hi I am trying to import VBA module for Outlook using Powershell. I know there is something for Excel but i dont see anything for Outlook when i searched.

    For Excel below is the blog that tells how to import module 

    https://social.technet.microsoft.com/Forums/office/en-US/f3bcd564-d7e0-4a80-bf4e-120eefc8ccd1/using-powershell-to-add-vba-to-an-excel-spreadsheet?forum=winserverpowershell

    But for Outlook i dont see anyway to add VBAcomponents like below

    VBProject.VBComponents
    Add-Type -AssemblyName Microsoft.Office.Interop.Outlook

    $Outlook = New-Object -ComObject Outlook.Application

    if we have similar in Outlook then it will be easy to distribute VBA modules to mulitple users using powershell script.

    Thursday, September 8, 2016 12:12 PM

Answers

  • Hello Shreekanth,

    The Outlook object model doesn't provide anything for dealing with VBA modules. Moreover, VBA macros are not designed for distributing the code on multiple PCs. You would have to copy the entire VBAProject.OTM file over and
    wipe out any existing macros or just add that code to each existing VBA project.

    The best and supported way is to create a COM addin to add the functionality
    you want. This what COM add-in were invented for. See Walkthrough: Creating Your First VSTO Add-In for Outlook for more information.


    [custom.development]

    • Proposed as answer by David_JunFeng Sunday, September 18, 2016 1:54 PM
    • Marked as answer by David_JunFeng Monday, September 19, 2016 5:21 AM
    Thursday, September 8, 2016 3:38 PM

All replies

  • Hello Shreekanth,

    The Outlook object model doesn't provide anything for dealing with VBA modules. Moreover, VBA macros are not designed for distributing the code on multiple PCs. You would have to copy the entire VBAProject.OTM file over and
    wipe out any existing macros or just add that code to each existing VBA project.

    The best and supported way is to create a COM addin to add the functionality
    you want. This what COM add-in were invented for. See Walkthrough: Creating Your First VSTO Add-In for Outlook for more information.


    [custom.development]

    • Proposed as answer by David_JunFeng Sunday, September 18, 2016 1:54 PM
    • Marked as answer by David_JunFeng Monday, September 19, 2016 5:21 AM
    Thursday, September 8, 2016 3:38 PM
  • Hi Shreekanth123,

    Outlook saves all macro code in a file named VbaProject.OTM. On a computer that has all the macro code, close Outlook and copy VbaProject.OTM. You can then copy that file to any other computer and it will have the same macro code that was on the computer it was copied from. Just be sure that each computer has the same version of Outlook and has macro security properly set.

    As same as Eugene's suggestion, Add-ins are their answer to sharing code.

    You could refer to this helpful link:

    https://www.experts-exchange.com/questions/28192469/Outlook-2010-Automate-import-of-macros-within-bas-file.html

    Disclaimer: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Thanks for your understanding.


    Friday, September 9, 2016 5:08 AM