Combo Box

Status
Not open for further replies.
As I mentioned earlier today and in the screencast , you use "With Combox7" and "ComboBox7" - they both need to be spelled the same as the name of the combobox control.
 
I did it, then in my contact form, I put the new macro of the Module7 as a bullet point on the Quick Access Tool Bar, and when I click on it, the userform shows up, and there is the list of the macros.

But the next step is to run one a macro from the list........as I can't figure out how to make it run when I identify the macro in the list of the combobox based on userform.....

So if there is a way to do that, everything is done.

Thanks so much for your great advice.
 
And also, given the macros are related to the emails and he contact itself, it was not clear to me what lines to add to the codes so the macros create the email to the contact.

Thanks very very much!! I am excited to finish this, as I have a number of macros in different email areas, so I can then create a new userform for each area once I know what lines to add as I mentioned here.
 
replace

Public Sub NewMessageUsingTemplate()

With these lines

Public oContact As Outlook.ContactItem
Public Sub NewMessageUsingTemplate()
If TypeName(ActiveExplorer.Selection.Item(1)) = "ContactItem" Then
Set oContact = ActiveExplorer.Selection.Item(1) ' this works with the selected item, not opened


replace

End Select

with these lines:

End Select
End if
Set oContact = Nothing


If you are referring to contacts in the macros as something besides oContact, then you need to change oContact to match. For example if you use olContact.Firstname in the other macros- this macro needs to use olContact too.
 
so if the code of the macro for the emails is oContact.EmailAddress, then that's what I put in this code...correct?

An the debug of what you gave shows the following where what i show as red this post, so you see it, is showing up as yellow:

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

Set oContact = ActiveExplorer.Selection.Item(1) ' this works with the selected item, not opened
 
Yes, if you use oContact in the other macros, you use it in this one.

The yellow means it is the problem line when you run the macro. What does the error message say?

Two things i know will cause problems - not selecting a contact and not adding the if statement.
 
The error says "expected: end of statement"

- - - Updated - - -

I emailed back to you from my notice if you can get the email back
 
the macro re emais is:

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

And the new macro we are working on right now so far is as follows:

Public lstNo As Long

Public oContact As Outlook.ContactItem

Public Sub NewMessageUsingTemplate()

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

Set oContact = ActiveExplorer.Selection.Item(1) ' this works with the selected item, not opened

UserForm1.Show
Select Case lstNo
Case -1
From_Lou_Stoler 'macro name
Case 0
From_Lou_Stoler_and_Vcard 'macro name
Case 1
Good_Morning_Catch_Up 'macro name
Case 2
Good_Afternoon_Catch_Up 'macro name
Case 3
Good_Morning_Catch_Up_to_Client 'macro name
Case 4
Good_Afternoon_Catch_Up_to_Client 'macro name
Case 5
Today_Meeting_Thank_You_Friend 'macro name
Case 6
Recent_Meeting_Thank_You_Friend 'macro name

End Select

End If

Set oContact = Nothing

End Sub

Private Sub From_Lou_Stoler()

MsgBox "From_Lou_Stoler"

End Sub

Private Sub From_Lou_Stoler_and_Vcard()

MsgBox "Good_Morning_Catch_Up"

End Sub

Private Sub Good_Morning_Catch_Up()

MsgBox "From_Lou_Stoler_and_Vcard"

End Sub

Private Sub Good_Afternoon_Catch_Up()

MsgBox "Good_Afternoon_Catch_Up"

End Sub

Private Sub Good_Morning_Catch_Up_to_Client()

MsgBox "Good_Morning_Catch_Up_to_Client"

End Sub

Private Sub Good_Afternoon_Catch_Up_to_Client()

MsgBox "Good_Afternoon_Catch_Up_to_Client"

End Sub

Private Sub Today_Meeting_Thank_You_Friend()

MsgBox "Today_Meeting_Thank_You_Friend"

End Sub

Private Sub Recent_Meeting_Thank_You_Friend()

MsgBox "Recent_Meeting_Thank_You_Friend"

End Sub

And the userform1 code is:

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
 
And I created inside the outlook template form, I added the macro to the Quick Access Bar of "NewMessageUsingTemplate" and when I click on it, the userform shows up, all the droplist per the above shows up and then i click on command next to it and it opens up a box that shows the name of the email form and when i click on that at the place "OK" it does not make the email
 
This worked for me - only case 0 has a working macro with it - i switched it so it opens a new message addressed to the contact, rather than use a template.

The others pop up the message box, "telling" me the combo box is working.

In one module:

Public lstNo As Long
Public oContact As Outlook.ContactItem
Public Sub NewMessageUsingTemplate()
If TypeName(ActiveExplorer.Selection.Item(1)) = "ContactItem" Then
Set oContact = ActiveExplorer.Selection.Item(1) ' this works with the selected item, not opened
UserForm1.Show
Select Case lstNo
Case -1
From_Lou_Stoler 'macro name
Case 0
From_Lou_Stoler 'macro name
Case 1
Good_Morning_Catch_Up 'macro name
Case 2
Good_Afternoon_Catch_Up 'macro name
Case 3
Good_Morning_Catch_Up_to_Client 'macro name
Case 4
Good_Afternoon_Catch_Up_to_Client 'macro name
Case 5
Today_Meeting_Thank_You_Friend 'macro name
Case 6
Recent_Meeting_Thank_You_Friend 'macro name
End Select
End If
Set oContact = Nothing
End Sub

' Remove these, or replace them with the template macro code.

' i only used them to test the code.
Private Sub From_Lou_Stoler_and_Vcard()
MsgBox "Good_Morning_Catch_Up"
End Sub
Private Sub Good_Morning_Catch_Up()
MsgBox "From_Lou_Stoler_and_Vcard"
End Sub
Private Sub Good_Afternoon_Catch_Up()
MsgBox "Good_Afternoon_Catch_Up"
End Sub
Private Sub Good_Morning_Catch_Up_to_Client()
MsgBox "Good_Morning_Catch_Up_to_Client"
End Sub
Private Sub Good_Afternoon_Catch_Up_to_Client()
MsgBox "Good_Afternoon_Catch_Up_to_Client"
End Sub
Private Sub Today_Meeting_Thank_You_Friend()
MsgBox "Today_Meeting_Thank_You_Friend"
End Sub
Private Sub Recent_Meeting_Thank_You_Friend()
MsgBox "Recent_Meeting_Thank_You_Friend"
End Sub

In another module:

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\Stole r 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

' you had GetCurrentItem6 here.
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
 
This is what I would do - everything in one module, one GetCurrentItem function.

Actually, I'd put the template name in the case and use 1 macro, like I did at VBA UserForm sample: Select from a list of templates - Slipstick Systems

Code:
Public lstNo As Long
Public oContact As Outlook.ContactItem
Public Sub NewMessageUsingTemplate()
If TypeName(ActiveExplorer.Selection.Item(1)) = "ContactItem" Then
Set oContact = ActiveExplorer.Selection.Item(1) ' this works with the selected item, not opened
UserForm1.Show
Select Case lstNo
Case -1
From_Lou_Stoler 'macro name
Case 0
From_Lou_Stoler 'macro name
Case 1
Good_Morning_Catch_Up 'macro name
Case 2
Good_Afternoon_Catch_Up 'macro name
Case 3
Good_Morning_Catch_Up_to_Client 'macro name
Case 4
Good_Afternoon_Catch_Up_to_Client 'macro name
Case 5
Today_Meeting_Thank_You_Friend 'macro name
Case 6
Recent_Meeting_Thank_You_Friend 'macro name
End Select
End If
Set oContact = Nothing
End Sub 
 
Private 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\Stole r 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
Private Sub From_Lou_Stoler_and_Vcard()
Set oContact = GetCurrentItem()
Dim objMsg As MailItem
' Blank message
 Set objMsg = Application.CreateItem(olMailItem)
' Use a template
'Set objMsg = Application.CreateItemFromTemplate("C:\Users\Stole r 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
Private Sub Good_Morning_Catch_Up()
 Set oContact = GetCurrentItem()
Dim objMsg As MailItem
' Blank message
 Set objMsg = Application.CreateItem(olMailItem)
' Use a template
'Set objMsg = Application.CreateItemFromTemplate("C:\Users\Stole r 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
Private Sub Good_Afternoon_Catch_Up()
Set oContact = GetCurrentItem()
Dim objMsg As MailItem
' Blank message
 Set objMsg = Application.CreateItem(olMailItem)
' Use a template
'Set objMsg = Application.CreateItemFromTemplate("C:\Users\Stole r 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
' repeat the private subs as needed
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
 
So this is macro in one module and stlll have the userform we created? correct?

And as a example, instead of the words Case -1
From_Lou_Stoler 'macro name

use the words for each case the template name.....and is it what is below correct? and the template name is file name but not ost?

strTemplate = "templatename -1"

Is this correct as well?
 
Yes, the module and the userform.

If you use the sample i have one the web site, you'll use something like this, where the filename is in the case.

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 = ActiveExplorer.Selection.Item(1)

Dim strTemplate As String
UserForm1.Show
Select Case lstNum
Case -1
strTemplate = "E-mail From Lou Stoler"
Case 0
strTemplate = "E-mail From Lou Stoler welcome"
Case 1
strTemplate = "E-mail From Lou Stoler billing"
Case 2
strTemplate = "Recent_Meeting_Thank_You_Friend"
Case 3
strTemplate = "Good_Afternoon_Catch_Up"
Case 4
strTemplate = "E-mail From Lou Stoler-6"
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

End Sub
 
I will go for it and let you know what happens. Thanks again so very much.
 
If you want it ot work with open or selected contacts, replace the similar lines in the macro with this and use the GetCurrentItem function.

If TypeName(ActiveExplorer.Selection.Item(1)) = "ContactItem" Then
Set oContact = GetCurrentItem()
 
I did it all and not working....

Is the case name the name of the macro (which is what is in it) or the full path of the C drive to the email temptate....for example: "C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\E-mail From Lou Stoler - Good Morning Catch-Up.oft"

And an error is that the words "Set oMail = Application.CreateItemFromTemplate(strTemplate)" are yellow and the error is that "File name or class name not found during automation operation.

And here is the full module.

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 = "E-mail_From_Lou Stoler"
Case 0
strTemplate = "From_Lou_Stoler_and_Vcard"
Case 1
strTemplate = "Good_Morning_Catch-Up"
Case 2
strTemplate = "Good_Afternoon_Catch_Up"
Case 3
strTemplate = "Good_Morning_Catch_Up_to_Client"
Case 4
strTemplate = "Good_Afternoon_Catch_Up_to_Client"
Case 5
strTemplate = "Today_Meeting_Thank_You_Friend"
Case 6
strTemplate = "Recent_Meeting_Thank_You_Friend"
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
 
This is the form and module I tested (with my own file paths and template names, i updated it to use yours). Right click on your form and module and remove them - use the option to save first so you can restore them if needed.




Unzip the file then go into the VBA editor and right click on project1 and import file. You'll need to import the templates.bas and userform1.frm.




I have a msgbox popping with the path to the template so you can see where it's looking for the template.




That is not the same error i get running your code (and I know the template doesn't exist here) and I'm not sure what the problem is.




View attachment templates.zip
 
thanks...i did it....the error again is:
Set oMail = Application.CreateItemFromTemplate(strTemplate) are yellow and the error is that "File name or class name not found during automation operation.

the case lines are the names of the macros....not the path to each email template......what should I change please?
 
Yes, use the template names, that is probably the cause of the error. (fingers crossed)
 
also.....I always got emails that you replied....but I don't get those notices anymore......is your system changed?

- - - Updated - - -

and is this the right full format for the template name: ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\E-mail From Lou Stoler - Good Morning Catch-Up.oft")
 
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