Outlook

josros60

Well-known Member
Joined
Jun 27, 2010
Messages
786
Office Version
  1. 365
HI I know this for outlook,

if any body can help me on this,

have this code in outlook to open combobox and it work when select the template nothing happens and sometimes get error run time error 432 and highlight this line: Set oMail = Application.CreateItemFromTemplate(strTemplate)

here it's the code:
Code:
Public Sub ChooseTemplate()


'Dim oMail As Outlook.MailItem
'im 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
'  -1 is what you want to use if nothing is selected
         strTemplate = "Requesting Payment"
    Case 0
         strTemplate = "C.C. Authorization2"
    Case 1
        strTemplate = "Payment Inquiry-Current_Pastdue2"
    Case 2
         strTemplate = "Payment Inquiry-Current_Pastdue_Aging."
    Case 3
         strTemplate = "Provide C.C. Information_2.oft"
    Case 4
         strTemplate = "Refund Approval"
    Case 5
         strTemplate = "Contra Approval"
    Case 6
         strTemplate = "Terminate Due to Non Payment"
    Case 7
         strTemplate = "Remittance Address"


    End Select


    strTemplate = "C:\Documents and Settings\rossj1\Application Data\Microsoft\Templates\" & strTemplate & ".oft"
    Set oMail = Application.CreateItemFromTemplate(strTemplate)


'With oMail
'  .To = oContact.Email1Address
' .ReadReceiptRequested = True
'  .Subject = "My Macro test"
 ' .Body = "Hi " & oContact.FirstName & "," & vbCrLf & vbCrLf & oMail.Body
 ' .Display
'End With
 ' End If
Set oMail = Nothing


End Sub


thank you
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Re: Outoook

It looks like you'll need to make a couple of changes to your Select Case statement. For Case 2, it looks like you'll need to remove the period (.) at the end of the string. And, for Case 3, it looks like you'll need to remove .oft from the end of that string. So probably...

Code:
    Select Case lstNum
    Case -1
'  -1 is what you want to use if nothing is selected
         strTemplate = "Requesting Payment"
    Case 0
         strTemplate = "C.C. Authorization2"
    Case 1
        strTemplate = "Payment Inquiry-Current_Pastdue2"
    Case 2
         strTemplate = "Payment Inquiry-Current_Pastdue_Aging"
    Case 3
         strTemplate = "Provide C.C. Information_2"
    Case 4
         strTemplate = "Refund Approval"
    Case 5
         strTemplate = "Contra Approval"
    Case 6
         strTemplate = "Terminate Due to Non Payment"
    Case 7
         strTemplate = "Remittance Address"


    End Select

Hope this helps!
 
Upvote 0
Re: Outoook

Thank you.

i don't get the run time error 432 after doing the changes, but nothing happen when i click the ok button won't open template.

here it's the other part of the code:

Code:
Private Sub UserForm_Initialize()  With ComboBox1
    .AddItem "Payment Required"
    .AddItem "Credit CardAuthorization"
    .AddItem "Past Due Amount"
    .AddItem "Suspend Account"
    .AddItem "Provide CC Information"
    .AddItem "Refund Approval"
    .AddItem "Contra Approval"
    .AddItem "Terminate Account"
    .AddItem "Remittance Address"
    


  End With
End Sub


Private Sub btnOK_Click()
    lstNum = ComboBox1.ListIndex
        Unload Me
    
End Sub

thanks again

Jose
 
Upvote 0
Re: Outoook

Did you delcare lstNum ? If so, in which module did you declare it, and how did you declare it?
 
Upvote 0
Re: Outoook

thank you,


not i haven't declare it, where should I declare it.


i am not that good in coding.


thanks for your help.
 
Upvote 0
Re: Outoook

You should declared it as a Public variable, and it should be declared in a regular/standard module, not in the userform module, at the beginning of the module, before any procedure...

Code:
Public lstNum As Integer

If your procedure called ChooseTemplate is located in a standard module, you can place the declaration in that module, before that or any other procedure.
 
Upvote 0
Re: Outoook

I declare it here but still doesn't work,

Code:
Public Sub ChooseTemplate()

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


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


Dim strTemplate As String
Dim lstNum As Integer
   UserForm1.Show


    Select Case lstNum

thanks
 
Upvote 0
Re: Outoook

As I mentioned, the variable should be declared as Public, and it should be place at the beginning of the module, like so...

Code:
Public lstNum As Integer

Public Sub ChooseTemplate()

'Dim oMail As Outlook.MailItem
'im 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

'etc
'
'
'
 
Upvote 0
Re: Outoook

thank you, but it's setup that way.

here it's the code:
Code:
Public lstNum As LongPublic Sub ChooseTemplate()


'Dim oMail As Outlook.MailItem
'im 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
'  -1 is what you want to use if nothing is selected
         strTemplate = "Requesting Payment"
    Case 0
         strTemplate = "C.C. Authorization2"
    Case 1
        strTemplate = "Payment Inquiry-Current_Pastdue2"
    Case 2
         strTemplate = "Payment Inquiry-Current_Pastdue_Aging"
    Case 3
         strTemplate = "Provide C.C. Information_2"
    Case 4
         strTemplate = "Refund Approval"
    Case 5
         strTemplate = "Contra Approval"
    Case 6
         strTemplate = "Terminate Due to Non Payment"
    Case 7
         strTemplate = "Remittance Address"


    End Select


    strTemplate = "C:\Documents and Settings\rossj1\Application Data\Microsoft\Templates\" & strTemplate & ".oft"
    'Set oMail = Application.CreateItemFromTemplate(strTemplate)


'With oMail
'  .To = oContact.Email1Address
' .ReadReceiptRequested = True
'  .Subject = "My Macro test"
 ' .Body = "Hi " & oContact.FirstName & "," & vbCrLf & vbCrLf & oMail.Body
 ' .Display
'End With
 ' End If
'Set oMail = Nothing


End Sub

and open the combobox but when i select the template from the list and click ok button close the combo but nothing happens.

thanks
 
Upvote 0
Re: Outoook

thank you, but it's setup that way.

But you didn't show that it was set up that way in your post...

and open the combobox but when i select the template from the list and click ok button close the combo but nothing happens.

Nothing happens for any of the selections? No error occurs?

I noticed, though, that your Select Case statement isn't set up correctly. It looks like it should be...

Code:
    Select Case lstNum
        Case -1, 0 'no selection or first selection
             strTemplate = "Requesting Payment"
        Case 1
             strTemplate = "C.C. Authorization2"
        Case 2
            strTemplate = "Payment Inquiry-Current_Pastdue2"
        Case 3
             strTemplate = "Payment Inquiry-Current_Pastdue_Aging"
        Case 4
             strTemplate = "Provide C.C. Information_2"
        Case 5
             strTemplate = "Refund Approval"
        Case 6
             strTemplate = "Contra Approval"
        Case 7
             strTemplate = "Terminate Due to Non Payment"
        Case 8
             strTemplate = "Remittance Address"
    End Select
 
Upvote 0

Forum statistics

Threads
1,223,705
Messages
6,173,996
Members
452,542
Latest member
Bricklin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top