1. Here's a thread that needs an answer: Outlook 2013 Forms Issue

Combo Box

Discussion in 'Using Outlook' started by LMS, Jan 26, 2013.

  1. LMS

    LMS

    Senior Member
    To summarze the past, please see below for the next possible steps

    I have found through great advice , a way to create set of email templates and a form of macro that when I single click on a contact in contact folder list, when I run the macro it creates an email based on the email template added to the macro and automatically adds the email address of the contact to the "To" bar of the email, so it automatically is set up to send the email to the contact I click on.

    Then I found a way to create a new menu bar as part of Outlook when you open Outlook, and add each macro as a part of menu bar so that when I click on the menu bar, I see a drop down list of each macro I can run, and if I have clicked on a contact (but not opening it), when I run the macro from the new menu bar, it does the same thing I mentioned above.

    In the contact template I created, I can add each macro to the Quick Access Toolbar, which creates a bullet in the contacts for each macro, and then when opening the contact, I can do the same as mentioned above as well.

    I have been told that there is no way to create a new menu bar in the contact template or a drop down list, so I don't have to have a long horizontel list of bullets to run the macros when I open a contact, , but have the new menu/drop down list just like it works in the new menu bar as part of Outlook when you open Outlook.

    So here is the next question:

    Under the contact template, you can include a Combo Box, so you create your own text field for the Combo Box, the List Type is a Dropdown, the Property t use is Value, and then under Possbile Values, you can type in a series of words and as each line words is separated by a ; each list of words shows up as a dropdown list to decide what to put in the field under your contact.

    So is there way under the Como Box , to put in the line of words which then when you on words, it runs a macro?

    Thanks to all.

     
  2. larry

    larry

    Senior Member
    I have not used combobox with macros, but they use case statements so you should be able to. The lady has a code sample at Select from a list of subjects before sending a message - Slipstick Systems that should point you in the right direction.

    Dim your object at the beginning -

    Dim oItem as Outlook.MailItem

    put this in the case statement -

    Set oItem = Application.CreateItem("C:\template.oft")

    put this is at the end of the case -

    oItem .Display

    You could use the case to assign variables, something like this:

    Case 0

    strTemplate = "templatename0"

    Case 1

    strTemplate = "templatename1"

    Dim oItem as Outlook.MailItem

    Set oItem = Application.CreateItem("C:\path\to\template\" & strTemplate & ".oft")

    oItem .Display

     
  3. LMS

    LMS

    Senior Member
    thanks for quick reply...but I can't figure out what and where you a telling me to add and what the other link says....all i did was create the UserForm1, add the combobox to his with the Caption Field named E-mail Template List, but I don't know what code to add, and how I add each macro....and then how find this UserForm1 on a Contact form...

    can you walk me thru this please so much!!

    Thanks

     
  4. Diane Poremsky

    Diane Poremsky

    Senior Member
    Have not tested Larry's suggestion but it looks good. If you are using a custom form with the combobox, you can use similar code. Create a button for NewMessageUsingTemplate macro and click it to call the userform and select templates.

    Private Sub Userform1_Initialize()

    ComboBox1.AddItem "Template 1"

    ComboBox1.AddItem "Template 2"

    ComboBox1.AddItem "Template 3"

    ComboBox1.AddItem "Template 4"

    ComboBox1.AddItem "Template 5"

    End Sub

    Private Sub CommandButton1_Click()

    lstNo = ComboBox1.ListIndex

    Unload Me

    End Sub

    Public lstNo As Long

    Public Sub NewMessageUsingTemplate()

    Dim oMail As Outlook.MailItem

    oMail.Display



    UserForm1.Show

    Select Case lstNo

    Case -1

    strTemplate = "templatename0"

    Case 0

    strTemplate = "templatename1"

    Case 1

    strTemplate = "templatename2"

    End Select

    Set oMail = Application.CreateItemFromTemplate("C:\path\to\template\" & strTemplate & ".oft")

    oMail .Display

    End Sub

     
    Last edited: Jan 26, 2013
  5. LMS

    LMS

    Senior Member
    Thanks so much. So this the code that I use for the UserForm1....where is says to create a code?

    And how do I create that button on the Contact?

    And as to the ComboBox1.AddItem "Template 1" areas, use the name of the macros or the template so that's what shows up?

    And as to areas: strTemplate = "templatename0"

    Case 0

    strTemplate = "templatename1"

    Case 1

    strTemplate = "templatename2"

    Put in the name of the macro's or the name of the template?

     
  6. Diane Poremsky

    Diane Poremsky

    Senior Member
    This: strTemplate = "templatename1" will use the template file name.

    Are you calling templates up or using macros to do something and open a template?

    oh, and the proper way to call a template is with CreateItemFromTemplate

    Set oMail = Application.CreateItemFromTemplate("c:\that\to\template.oft")

     
  7. Diane Poremsky

    Diane Poremsky

    Senior Member
  8. LMS

    LMS

    Senior Member
    To make this clear. I am trying use the combo box so it shows all the macros that I have created and I can just pick the macro I want to run.

    So what is the code that I should use so it goes to each macro as part of the combo box?

     
  9. Diane Poremsky

    Diane Poremsky

    Senior Member
    To run macros, you'll use Call macro_name or just macro_name in the Case line. If the macros are identical except for the template name, something like what i have on the website would be better.

    Case 0

    macro_name1

    Case 1

    macro_name2

     
  10. LMS

    LMS

    Senior Member
    Thank you very much.

    Can you possibly just post the full code that I copy and past and wherever you put the word macro_name1 or macro_name2 etc., I will change it to the macro name of each macro.

    I truly appreciate your help over the last couple of months as it has been wonderful and has helped me so so much!!

     
  11. Diane Poremsky

    Diane Poremsky

    Senior Member
    try something like this

    Public Sub ChooseTemplate()

    Dim oMail As Outlook.MailItem

    Dim oContact As Outlook.ContactItem

    Dim strTemplate As String

    UserForm1.Show

    Select Case lstNum

    Case -1

    macro_1

    Case 0

    macro_2

    Case 1

    macro_3

    Case 2

    macro_4

    Case 3

    macro_5

    Case 4

    macro_6

    End Select

    End Sub

     
  12. LMS

    LMS

    Senior Member
    thanks much...i will try it......

    the first line of the first macro says: Public Sub From_Lou_Stoler()

    So what is the macro name please? is it From_Lou_Stoler() or From Lou_Stoler

     
  13. LMS

    LMS

    Senior Member
    and see below as to Case -1 and tell me please the name of the macro and do I add the _1 at the end of it?:

    Select Case lstNum

    Case -1

    From_Lou_Stoler_1

    Case 0

    macro_2

    Case 1

    macro_3

    Case 2

    macro_4

    Case 3

    macro_5

    Case 4

    macro_6

    End Select

     
  14. Diane Poremsky

    Diane Poremsky

    Senior Member
    macro name would be From Lou_Stoler

    - - - Updated - - -

    if the macro name is

    public sub From_Lou_Stoler_1()

    then you'd use From_Lou_Stoler_1

     
  15. LMS

    LMS

    Senior Member
    It is public sub....so I did the following to try the first one and when I save it and then run it, the combo box shows up, I click on the side, and it opens up a the downlist, but nothing shows up in the downlist

    Public Sub ChooseTemplate()

    Dim oMail As Outlook.MailItem

    Dim oContact As Outlook.ContactItem

    Dim strTemplate As String

    UserForm1.Show

    Select Case lstNum

    Case -1

    From Lou_Stoler_1

    Case 0

    macro_2

    Case 1

    macro_3

    Case 2

    macro_4

    Case 3

    macro_5

    Case 4

    macro_6

    End Select

    End Sub

    Private Sub CommandButton1_Click()

    End Sub

    Private Sub UserForm_Click()

    End Sub

    And the macro that works when when I use it in the ways you showed me.....the macro is as follows:

    Public Sub From_Lou_Stoler()

    Set oContact = GetCurrentItem()

    Dim objMsg As MailItem

    ' Blank message

    ' Set objMsg = Application.CreateItem(olMailItem)

    ' Use a template

    Set objMsg = Application.CreateItemFromTemplate("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\E-mail From Lou Stoler.oft")

    objMsg.To = oContact.Email1Address

    'displays the message form so you can enter more text

    objMsg.Display

    'use this to send to outbox

    'objMsg.Send

    Set objMsg = Nothing

    End Sub

    Function GetCurrentItem2() As Object

    Dim objApp As Outlook.Application



    Set objApp = Application

    On Error Resume Next

    Select Case TypeName(objApp.ActiveWindow)

    Case "Explorer"

    Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)

    Case "Inspector"

    Set GetCurrentItem = objApp.ActiveInspector.CurrentItem

    End Select



    Set objApp = Nothing

    End Function

     
  16. Diane Poremsky

    Diane Poremsky

    Senior Member
    Did you declare

    Public lstNo As Long in the macro with the chooseForm macro?

    it needs to match the variable in the command_click macro in the userform -

    lstNo = cbList.ListIndex

     
  17. LMS

    LMS

    Senior Member
    thank for the details....but as i said before....i am not the technical person....so I don't understand what means declare.....and how something matches.....can you walk me thur the process as I showed you the code you gave me....and the macro that it refers to....also, the macro name did not include the _1, so that is not in the code...

    which means....i don't undertand what to do next....as i don't know the concepts you mentioned

     
  18. Diane Poremsky

    Diane Poremsky

    Senior Member
    This is what the code should look like in the editor - the first line declares lstNo as a number (long). Then the macro follows and each Case calls a different macro. In my quickie example, i open a new message form and popup a msgbox.

    macro.png

     
  19. LMS

    LMS

    Senior Member
    so is this what I should copy and past and just fill in the macro names from the top of each macro?

     
  20. Diane Poremsky

    Diane Poremsky

    Senior Member
    Yeah, pretty much. Your VBA will be something like this, since you are calling the template from the other macros.

    Code (Text):
    Copy Source
     
     
    Public lstNo As Long
     
     Public Sub NewMessageUsingTemplate()
     
     Dim oMail As Outlook.MailItem
     
     UserForm1.Show
     
     Select Case lstNo
     
     Case -1
     
    macro1
     
     Case 0
     
    macro2
     
     Case 1
     
    macro3
     
     End Select
     
     End Sub


     
Similar Threads
Forum Title Date
Outlook VBA and Custom Forms Contact Page 2 Combobox via Registry Oct 5, 2014
Using Outlook Outlook 2010 - outlook userform and combo boxes Jun 1, 2014
Using Outlook Is it an address book or a contact folder, I'm discombobulated? May 25, 2014
Using Outlook Outlook form - Combo box for deciding who to send form to Feb 9, 2014
Using Outlook Combox AddItem Jan 3, 2014

Share This Page