none
Having difficulty creating a macro in Outlook Microsoft VB for Applications (creating macro for outlook email template) RRS feed

  • Question

  • I attempted to follow an online tutorial for creating a macro in Outlook but I keep getting a "compile error: expected list separator ( or blank."

    Below is my code. 

    Sub MakeItem()
    Set newItem = Application.CreateItemFromTemplate(C:\Users\Scott\Documents\Custom Office Templates\Outlook Templates\CM Delivery - Invoice PO.oft)
    newItem.Display
    Set newItem = Nothing
    End Sub

    I am sure it is a simple fix. Any help is appreciated. 

    Sunday, March 29, 2015 3:53 AM

Answers

  • The file name must be in quotes

    Sub MakeItem()
     Set newItem = Application.CreateItemFromTemplate("C:\Users\Scott\Documents\Custom Office Templates\Outlook Templates\CM Delivery - Invoice PO.oft")
     newItem.Display
     Set newItem = Nothing
     End Sub


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    • Marked as answer by Pottery_Pal Monday, March 30, 2015 2:47 AM
    Sunday, March 29, 2015 4:53 AM

All replies

  • The file name must be in quotes

    Sub MakeItem()
     Set newItem = Application.CreateItemFromTemplate("C:\Users\Scott\Documents\Custom Office Templates\Outlook Templates\CM Delivery - Invoice PO.oft")
     newItem.Display
     Set newItem = Nothing
     End Sub


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    • Marked as answer by Pottery_Pal Monday, March 30, 2015 2:47 AM
    Sunday, March 29, 2015 4:53 AM
  • Hello Pottery,

    You may find the CreateItemFromTemplate method of the Application class described in MSDN with a sample code. Note, the method can accept .msg files as well, not only .oft.

    Also I'd recommend reading the Getting Started with VBA in Outlook 2010 article.

    Sunday, March 29, 2015 6:46 AM