Opening Outlook Template in Excel VBA

tonycm1

New Member
Joined
Aug 25, 2007
Messages
47
Alright, I've been researching this for the last few hours without much luck. Essentially, I've written some VBA for excel that does all the work I need but I would then like it to open an outlook template (OTF) file so that I can e-mail these attachments.

I have this code already in an outlook macro but it doesn't work when I copy/paste it in excel... the code is the following:

'Sub Open_Login_Logout()
'
'Set myItem = Application.CreateItemFromTemplate _
' ("M:\Reporting Templates\Metrics Shortcuts\Login Logout.oft")
' myItem.Display
'
' Set myAttachments = myItem.Attachments
' myAttachments.Add "M:\Reporting Templates\Custom Reports\Tony\HCLL02FEB08.xls", _
' olByValue, 1
' myAttachments.Add "M:\Reporting Templates\Custom Reports\Tony\NSDLL02FEB08.xls", _
' olByValue, 2
' myAttachments.Add "M:\Reporting Templates\Custom Reports\Tony\OSSDLL02FEB08.xls", _
' olByValue, 3
'
'End Sub

I've also found this site http://www.codeforexcelandoutlook.com/olAutomation.html that I thought would have solved my dileama with the following code:

Sub CreateMailInExcel()
Dim olApp As Outlook.Application
Dim Msg As Outlook.MailItem

Set olApp = New Outlook.Application

Set Msg = olApp.CreateItem(olMailItem)

Msg.Display

Set Msg = Nothing
Set olApp = Nothing
End Sub

BUT.... the code stops working when it fails to find Outlook.Application

I'm running Excel 2000 and Outlook 2003 (i know that's a dumb setup, but it's the only thing allowed at work).

Ideas?????????
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Solved my own question. Here's the code for future reference... just 6 lines of code :)

Sub OutlookTemplate()

Dim myolapp As Object
Dim myitem As Object

Set myolapp = CreateObject("Outlook.Application")
myolapp.Session.Logon

Set myitem = myolapp.CreateItemFromTemplate("C:\test.oft")
myitem.Display 'or send

End Sub
 
Upvote 0
Solved my own question. Here's the code for future reference... just 6 lines of code :)

Sub OutlookTemplate()

Dim myolapp As Object
Dim myitem As Object

Set myolapp = CreateObject("Outlook.Application")
myolapp.Session.Logon

Set myitem = myolapp.CreateItemFromTemplate("C:\test.oft")
myitem.Display 'or send

End Sub


i have 4 different template and i want to send each template with bind with Email id list ..

can you help me create macro which work in below excel file . ..

To
CCtemplate Location
Attachment
Location
abc@abc.comxyz@xyz.comC:/1.oftC:/1.xls
test@test.comhelp@help.comC:/2.oftC:/2.xls

<colgroup><col span="2"><col><col></colgroup><tbody>
</tbody>


thanks in advance.

amit bhatt
 
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,530
Members
448,969
Latest member
mirek8991

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