简体   繁体   中英

Generate new email from a custom outlook form

I have built a form that stores certain contact data on it. I want to include a couple of buttons/functions to keep the user in the form as much as possible versus switching between Outlook components (calendar, mail, etc.).

In this case the user can swap email addresses from separate ListBoxes and when they hit the button it will use the emails within one of them. Using VBS because I'm dealing with custom Outlook forms.

Sub GenerateButton_Click()
     'Generates Email with all of the CCs

     'Variables
     Set FormPage = Item.GetInspector.ModifiedFormPages("Commands")
     Set DoSend = FormPage.Controls("DoSendListBox")
     mailList = ""

     'Generate Email List
     For x = 0 to (DoSend.ListCount - 1)
         mailList = mailList & DoSend.List(x) & ";"
     Next

     'Compose Email
     Set msg = Application.CreateItem(olMailItem)
     msg.Subject = "Hello World!"
     msg.To = mailList
End Sub  

What Happens
- it compiles
- nothing happens on click

Research
- online forums usually in VBA
- relevant articles use outside connection rather than from within outlook

SOLVED
Note: Click on the "script" option and select the object item. From the new window you can navigate through the classes and from this I was able to find MailItem . You can see all of the methods/properties on the right hand pane.

It Turns out the correct syntax was:

Set msg = Application.CreateItem(MailItem)
msg.Display

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM