Combo Box

Status
Not open for further replies.
Nothing changed on the forum. Spam filters are known to filter VBA code or short messages, so if you get some but not others, look in the junk folder.

Assuming that is the template name and where it was saved to, yes, that would be correct.
 
And should I use the same template name and where it is saved to for the userform code as below, or is each Additem just a title re each template from the module?

Private Sub ComboBox1_Change()

End Sub

Private Sub ComboBox7_Change()

End Sub

Private Sub UserForm_Initialize()

With ComboBox7
.AddItem "From_Lou_Stoler"
.AddItem "From_Lou_Stoler_and_Vcard"
.AddItem "Good_Morning_Catch_Up"
.AddItem "Good_Afternoon_Catch_Up"
.AddItem "Good_Morning_Catch_Up_to_Client"
.AddItem "Good_Afternoon_Catch_Up_to_Client"
.AddItem "Today_Meeting_Thank_You_Friend"
.AddItem "Recent_Meeting_Thank_You_Friend"
End With
End Sub

Private Sub CommandButton4_Click()
lstNo = ComboBox7.ListIndex
Unload Me
End Sub
 
The names in the combo box can be "friendly names" - they serve one purpose - so you know which one to pick.
 
Same debug re the yellow words.....Set oMail = Application.CreateItemFromTemplate(strTemplate)

Public lstNum As Long

Public Sub ChooseTemplate()

Dim oMail As Outlook.MailItem
Dim oContact As Outlook.ContactItem

If TypeName(ActiveExplorer.Selection.Item(1)) = "ContactItem" Then
Set oContact = GetCurrentItem()

Dim strTemplate As String
UserForm1.Show

Select Case lstNum
Case -1
strTemplate = ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\E-mail From Lou Stoler.oft")
Case 0
strTemplate = ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\E-mail From Lou Stoler and Vcard.oft")
Case 1
strTemplate = ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\E-mail From Lou Stoler - Good Morning Catch-Up.oft")
Case 2
strTemplate = ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\E-mail From Lou Stoler - Good Afternoon Catch-Up.oft")
Case 3
strTemplate = ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\E-mail From Lou Stoler - Good Morning Catch-Up to Client.oft")
Case 4
strTemplate = ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\E-mail From Lou Stoler - Good Afternoon Catch-Up to Client.oft")
Case 5
strTemplate = ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\E-mail From Lou Stoler - Today Follow-Up From Inital Event Introduction.oft")
Case 6
strTemplate = ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\E-mail From Lou Stoler - Recent Follow-Up From Inital Event Introduction.oft")
End Select

strTemplate = "C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\" & strTemplate & ".oft"
Set oMail = Application.CreateItemFromTemplate(strTemplate)

With oMail
.To = oContact.Email1Address
.Display
End With
End If
Set oMail = Nothing

End Sub

Function GetCurrentItem() 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
 
You are duplicating the path

Case 6
strTemplate = ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\E-mail From Lou Stoler - Recent Follow-Up From Inital Event Introduction.oft")

and

strTemplate = "C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\" & strTemplate & ".oft"
Set oMail = Application.CreateItemFromTemplate(strTemplate)

if you are using the full path in the case statements, you don't need the second strTemplate line that sets the path - delete it.
 
thanks again....so please be clear to me ....what words do I delete from the module please?

Just: strTemplate = "C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\" & strTemplate & ".oft"

or both: strTemplate = "C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\" & strTemplate & ".oft"
Set oMail = Application.CreateItemFromTemplate(strTemplate)
 
just strTemplate = "C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\" & strTemplate & ".oft"

the other one tells outlook to create a new message from the template.

if all of the templates are in the same folder, you could keep that line and remove the path from the case statements. The .oft part can be in one lines or the other - its only 4 characters and is not a big deal id its in the case statement.
 
I did it and when I click in each different name in the combo box, and run it, each one opens up an email to the contact I am in, but uses the same template from:
(strTemplate = ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\E-mail From Lou Stoler and Vcard.oft")

and does not got to any other template that is a part of the macro in the module.......

so what to fix now?

thanks
 
if it works with the full path in the case statements, use it. It should work the other way too, but I'm not sure why its not.
 
Please see below, as what I did, is when I changed a case number to 0 and the original case 0 to a number of the case I changed to 0, the click the combobox just goes to whatever template is in Case 0.

So do you have any thoughts to fix it now?

Here is the useform code:

Private Sub ComboBox1_Change()

End Sub

Private Sub ComboBox7_Change()

End Sub

Private Sub UserForm_Initialize()

With ComboBox7
.AddItem "From_Lou_Stoler"
.AddItem "From_Lou_Stoler_and_Vcard"
.AddItem "Good_Morning_Catch_Up"
.AddItem "Good_Afternoon_Catch_Up"
.AddItem "Good_Morning_Catch_Up_to_Client"
.AddItem "Good_Afternoon_Catch_Up_to_Client"
.AddItem "Today_Meeting_Thank_You_Friend"
.AddItem "Recent_Meeting_Thank_You_Friend"
End With
End Sub

Private Sub CommandButton4_Click()
lstNo = ComboBox7.ListIndex
Unload Me
End Sub

Here is the module code:

Public lstNum As Long

Public Sub ChooseTemplate()

Dim oMail As Outlook.MailItem
Dim oContact As Outlook.ContactItem

If TypeName(ActiveExplorer.Selection.Item(1)) = "ContactItem" Then
Set oContact = GetCurrentItem()

Dim strTemplate As String
UserForm1.Show

Select Case lstNum
Case -1
strTemplate = ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\E-mail From Lou Stoler.oft")
Case 0
strTemplate = ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\E-mail From Lou Stoler and Vcard.oft")
Case -1
strTemplate = ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\E-mail From Lou Stoler - Good Morning Catch-Up.oft")
Case 2
strTemplate = ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\E-mail From Lou Stoler - Good Afternoon Catch-Up.oft")
Case 3
strTemplate = ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\E-mail From Lou Stoler - Good Morning Catch-Up to Client.oft")
Case 4
strTemplate = ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\E-mail From Lou Stoler - Good Afternoon Catch-Up to Client.oft")
Case 5
strTemplate = ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\E-mail From Lou Stoler - Today Meeting Thank-You - Friend.oft")
Case 6
strTemplate = ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\E-mail From Lou Stoler - Recent Meeting Thank-You - Friend.oft")
End Select
Set oMail = Application.CreateItemFromTemplate(strTemplate)

With oMail
.To = oContact.Email1Address
.Display
End With
End If
Set oMail = Nothing

End Sub

Function GetCurrentItem() 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
 
in the userform:

lstNo = ComboBox7.ListIndex

in the macro:

Public lstNum As Long

Select Case lstNum

everything needs to match to work. :)
 
Those are the words in both the userform and macro per what you see I posted....i am confused...what should and where should i fix what? thanks so much as usual!!
 
You need to use either lstNum or lstNo both places. The userform is assigning a value to lstNo but the macro isn't using it. The macro is looking for a value in lstNum, which is 0.
 
I did what you said to do, and used lstNum and there is the entire story:

Here is the history and the errors:

In the contact template form, I got to Customize Quick Access Toolbar, and then add the macro named "Choose Template", and when I click on it in any contact, the userform1 shows up and there is the Commandbutton4 to the left side, and then the Combobox7 to the right side of the userform1.

There is the droplist of each AddItem from the Userform that shows up in the Combobox7.

The AddItem list is in this order from the userform1:

> AddItem "From_Lou_Stoler"
.AddItem "From_Lou_Stoler_and_Vcard"
.AddItem "Good_Morning_Catch_Up"
.AddItem "Good_Afternoon_Catch_Up"
.AddItem "Good_Morning_Catch_Up_to_Client"
.AddItem "Good_Afternoon_Catch_Up_to_Client"
.AddItem "Today_Meeting_Thank_You_Friend"
.AddItem "Recent_Meeting_Thank_You_Friend"

and here is what happens with each click of each AddItem

Click on: "From_Lou_Stoler"

It runs the template: ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\E-mail From Lou Stoler and Vcard.oft") from Case 0 which is the next template below the template it is supposed to run.

Click on: "From_Lou_Stoler_and_Vcard"

Invalid procedure or argument and the debug shows "Set oMail = Application.CreateItemFromTemplate(strTemplate)" in yellow

Click on: "Good_Morning_Catch_Up"

It runs the template: ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\E-mail From Lou Stoler - Good Afternoon Catch-Up.oft") from Case2 which is the next template below the template it is supposed to run.

Click on: "Good_Afternoon_Catch_Up"

It runs the template: ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\E-mail From Lou Stoler - Good Morning Catch-Up to Client.oft") from Case3 which is the next template below the template it is supposed to run.

Click on: "Good_Morning_Catch_Up_to_Client"

It runs the template: ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\E-mail From Lou Stoler - Good Afternoon Catch-Up to Client.oft") from Case 4 which is the next template below the template it is supposed to run.

Click on: "Good_Afternoon_Catch_Up_to_Client"

It runs the template: ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\E-mail From Lou Stoler - Today Meeting Thank-You - Friend.oft") which is the next template below the template it is supposed to run.

Click on: "Today_Meeting_Thank_You_Friend"

It runs the template: ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\E-mail From Lou Stoler - Recent Meeting Thank-You - Friend.oft") from Case5 which is the next template below the template it is supposed to run.

Click on: "Recent_Meeting_Thank_You_Friend"

Invalid procedure or argument and the debug shows "Set oMail = Application.CreateItemFromTemplate(strTemplate)" in yellow
 
On the two yellow errors: copy the template path and make sure it works.

The templates should be in case 0 - case 6 or whatever. Case -1 is what you want to do if nothing is selected - ie, use the template you want to use as default.
 
You are still the best!!!

It is now working and I have a droplist in my contact form!!!

PS, if I create a second userform and just have a different list email templates, other than the number of the comandbutton and combobox and name of the module, just create the additems and the related paths to templates....correct?

PSS. would love to thank you over phone if can at some point!!!
 
Yes, you need the add items and the templates in the case statement. Only the userform really needs a new name - Private means they only work within that module or form. So command button and combo box can use the same names as long as they are in different forms. The main macro & the userform will need a new name. If that makes sense... I'm tired and may not be typing straight. :)
 
In the new Module8 I changed the name Public Sub ChooseTemplateto Thank_You_Emails ()

and I changed:

Dim strTemplate

As String UserForm1.Show

to:

Dim strTemplate As String

UserForm2.Show

I made sure that the Name of the CommandButton is CommandButton4and the name of the ComboBox is ComboBox7 each one which is the names of the first one we put together



And the name of the userform is userform2



And the error shows up as follows:



Ambiguous name detected - 1stNum



and Private SubCommandButton4_Click() is yellow and



lstNum of 1stNum = ComboBox7.ListIndex is blue



and: when i run thefirst userform, it is now the same errors.



Any thoughts on what to fix?

 
Each userform needs to use a different variable - you'll need to use something else for lstNum in the second userform and macro.
 
Thanks very much as usual!!

Is lstNum the number one before the words stNum? or is it the letter l?

And can I add a number to the end of it so it would be lstNum2 ??

thanks so much...this is great!
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
R List folders in a combo box + select folder + move emails from inbox to that folder + reply to that email Outlook VBA and Custom Forms 1
G Using Data From Combo Box in Appointment Body Outlook VBA and Custom Forms 6
P Custom Outlook form_Validations in combo box Outlook VBA and Custom Forms 0
S Outlook form - Combo box for deciding who to send form to Using Outlook 1
M details with the combo box Exchange Server Administration 3
Q Follow up: Make a combo box dependant on another Outlook VBA and Custom Forms 6
Q Make a combo box dependant on another Outlook VBA and Custom Forms 5
Q Load a recipient based on a value in a combo box Outlook VBA and Custom Forms 7
F Outlook 2010 - outlook userform and combo boxes Using Outlook 9
M Need help with combo boxes in messages! Using Outlook 10
M Outlook 2007 / Vista / Windows XP best combo needed BCM (Business Contact Manager) 2
P turn off the default "all day" check box in new calendar items. How? Using Outlook 1
S New Email "From" box stopped working Using Outlook 0
T Outlook 365 Search Box reverting to old location Using Outlook 2
J How do you disable address search box when typing @ in body of email? Using Outlook 0
L Is there a way to completely disable the "archive" box? Using Outlook 1
M Reverting The Outlook Search Box Location (or other undesired additions) Using Outlook 1
P outlook 2008 search box criteria couldn't be saved Using Outlook 2
Terry Sullivan E-Mails Sent Using a Group Box Result in 70 Kickbacks Using Outlook 4
N Private check box in table view Using Outlook 0
Commodore Folders always closed in move/copy items dialog box Using Outlook 3
P IMAP Folders Dialog Box Using Outlook 1
C Custom Outlook Form - Populate Information from Radio Button / Check Box Using Outlook 0
J Program Checkbox that will activate a text box in a Outlook fallible form. Outlook VBA and Custom Forms 1
CWM030 Call me old if you want. OL 2016 font size out of the box. Using Outlook 3
P Suppress dialog box on email check error? Using Outlook 5
E Don't want Inbox shown when login box is shown Using Outlook 1
stephen li VBA Outlook send mail automatically by specified outlook mail box Outlook VBA and Custom Forms 1
A GetSelectNamesDialog Pre-fill search box Outlook VBA and Custom Forms 12
P Outlook 2010 sending safe senders email to junk box Using Outlook 8
K Sharedmail box Outlook VBA and Custom Forms 4
Diane Poremsky Outlook Suggestion Box at Uservoice Using Outlook 0
D Emails do not appear in Sent box! Using Outlook 4
T OL2010 Password box keeps appearing. Using Outlook 6
A From box in custom outlook Form Outlook VBA and Custom Forms 0
Kristine RS box added in Favorites disappears Using Outlook 6
L An () has been inserted after the address in an address box; how do I remove them. Using Outlook 1
rohit I want to Populate Popup box while sending any email with attachment. Outlook VBA and Custom Forms 4
rohit I want to Populate Popup box while sending any email with attachment Using Outlook 1
moron save as & file location dialog box popup Outlook VBA and Custom Forms 2
Ross Garvey Dialogue box opens as I exit Using Outlook 2
P BCM 2013 Contacts Form Drop Down Box Bug BCM (Business Contact Manager) 1
C Outlook 2013 - Email Gets Sent - But Does Not Move From Outbox to Sent Box Using Outlook 4
G Enter Network Password box pops up every few seconds Using Outlook 2
V In Box Issues Using Outlook 1
S 2010 outlook today looks like an empty email box Using Outlook 4
S Custom yes/no message box. Using Outlook 0
L Auto-set followup/reminder popup box for ALL sent emails. Using Outlook 0
P VBA for Dialog Box when sending Email Using Outlook 8
V Clicking box to delete junk mail doesn't stay Using Outlook 2

Similar threads

Back
Top