Results 1 to 2 of 2

Thread: How to open Outlook form with VB code

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2005
    Posts
    9

    How to open Outlook form with VB code

    Hi,
    I have an Outlook public form that I want to open with VB code.
    I've found here the next script, but I don't know what's the path to the form (I choose it from organizational forms library).
    How can I found out the path? Is there another way to do it?

    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim oApp As Outlook.Application
    3.     Dim oMsg As Outlook.MailItem
    4.  
    5.     Set oApp = New Outlook.Application
    6.     Set oMsg = oApp.CreateItemFromTemplate("D:\Development\Outlook\Outlook Template\Message Test.oft")
    7.     If Not oMsg Is Nothing Then
    8.         oMsg.Display vbModal
    9.     Else
    10.         MsgBox "Couldnt find your template!"
    11.     End If
    12.     oApp.Quit
    13.     Set oApp = Nothing
    14. End Sub

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to open Outlook form with VB code

    I remember that code

    If you have a custom form that is not saved to the file system then you can create a new item in the folder that has that form as its default form. You can always .Move the item after if need be.

    VB Code:
    1. Dim oApp As Outlook.Application
    2.     Dim oMsg As Outlook.MailItem
    3.     Dim oFolder As Outlook.MAPIFolder
    4.    
    5.     Set oApp = New Outlook.Application
    6.     Set oFolder = oApp.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Folders("MySubFolderWithMyCustomForm")
    7.     Set oMsg = oFolder.Items.Add
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

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



Click Here to Expand Forum to Full Width