Outlook

josros60

Well-known Member
Joined
Jun 27, 2010
Messages
588
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

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

josros60

Well-known Member
Joined
Jun 27, 2010
Messages
588
Office Version
  1. 365
Re: Outoook

Yes I did, stillnot working,

here is the complete if you please can help me, would make my work easier because i do lots of emails,

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

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
Dim lstNum As Integer
    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


    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


thanks
 

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
19,720
Re: Outoook

Okay, let's see what's happening. First, in your procedure called ChooseTemplate, set a breakpoint at the line that says End Sub. You can do this one of two ways. You can either click next to the End Sub statement in the left margin indicator bar, or you can position your cursor in the End Sub line, and press F9 or click Toggle Breakpoint from the Debug menu. Then run ChooseTemplate. The macro should stop at the End Sub line. Then, first type the following line in the Immediate Window (Ctrl+G), and press Enter...

Code:
? strTemplate

And then type the following line in the Immediate Window, and press Enter...

Code:
? dir(strTemplate, vbNormal)

What do you get for both of the above?

By the way, I'm going to leaving soon, so I may not be able to get back to you until sometime later.
 

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
19,720

ADVERTISEMENT

Re: Outoook

Also, I'm assuming that you've already checked to make sure that the .oft files exist (ie. Requeting Payment.oft, C.C. Authorization2.oft, Payment Inquiry-Current_Pastdue2.oft, etc.), and that they exist in the specified folder, correct?
 

josros60

Well-known Member
Joined
Jun 27, 2010
Messages
588
Office Version
  1. 365
Re: Outoook

thanks.

Yes the templates oft files exist.

when type in the windows:

? strTemplate it's fine but when type

? dir(strTemplate, vbNormal) get run time error 13, mismtach

thanks



</pre>
 

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
19,720

ADVERTISEMENT

Re: Outoook

when type in the windows:

? strTemplate it's fine...

But what string does it actually return?

Also, I see that when you post your code, you comment out some lines of code. I'm assuming that you uncomment those lines when testing, correct? If not, make sure that you do so when testing.
 

josros60

Well-known Member
Joined
Jun 27, 2010
Messages
588
Office Version
  1. 365
Re: Outoook

On the first one when I press enter nothing happens
But on the second one when I press enter give run time error 13 mistmatch

Thank you
 

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
19,720
Re: Outoook

On the first one when I press enter nothing happens

That means that the variable has not been assigned a value. And, in taking another look at your last code that you posted, I see why. For some reason, you've put back the declaration for lstNum (ie. Dim lstNum as Integer) within the ChooseTemplate procedure. You'll need to remove it, since we've now declared it as a public variable at the beginning of the module.
 

josros60

Well-known Member
Joined
Jun 27, 2010
Messages
588
Office Version
  1. 365
Re: Outoook

Thank you for answering all my questions.

I removed this line:
Code:
[COLOR=#333333]Dim lstNum As Integer[/COLOR]

still doesn't work.

thanks again
 

Forum statistics

Threads
1,141,062
Messages
5,704,062
Members
421,326
Latest member
pfaustino

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
Top