Open Email template with VBA from Excel


"Excel VBA Help"

 


Play Friv Now - Play Friv Games
Go Back   The Code Cage Forums > Microsoft Topics > Microsoft Excel Forum
Our Info Pages:-
The Code Cage - Microsoft Office help

Notices

Microsoft Excel Forum Members Post questions in this forum if they are related to using Microsoft Excel, this includes Worksheet Functions, Excel VBA Programming, Simple Macro Code & Charting, Excel formula etc.

New Reply
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
  #1  
Unread 20th September 2010, 06:13
Mhuddles1981's Avatar
Mhuddles1981 Mhuddles1981 is offline
Junior Member
MS Office Version: MS Office 2003
MS Office Skill Level: Can use VBA
 
Join Date: Aug 2010
Location: Townsville
Age: 33
Posts: 77
Posts Per Day: 0.05
My Top Tip Count: 0
Thanks to others: 16
Thanked 1 Time in 1 Post
Reputation: 20 (5) Mhuddles1981 is on a distinguished road
Australia
Default Open Email template with VBA from Excel
     Excel: VBA   


------ Register to get rid of these "In Post" ads! ------

Category: Excel: VBA   

Hi,

I'm trying to track down the code to open a email template (.Oft) from excel VBA then populate the address from a range of cells (B3:B7)

then copy the range A16 to a text box in the email template

Does anyone have a clue how to do this?

I seem to find alot about creating new emails and then adding the receipient but nothing about open an .oft file.

Any help is appreciated

Cheers

The Code Cage Advertisment
Advertisement
  #2  
Unread 21st September 2010, 17:19
Death's Avatar
Death Death is offline
Junior Member
MS Office Version: MS Office 2003, 2007
MS Office Skill Level: Some VBA experience
 
Join Date: Sep 2010
Location: Royal Leamington Spa, Warwickshire
Posts: 14
Posts Per Day: 0.01
My Top Tip Count: 0
Thanks to others: 4
Thanked 4 Times in 3 Posts
Reputation: 70 (5) Death will become famous soon enough
Scotland
Default Re: Open Email template with VBA from Excel

------ Register to get rid of these "In Post" ads! ------


Have you tried outlookcode.com? (sorry - I'd post a link but it won't let me until I've posted 5 times! )

------------------------------ posted before receiving a reply after 5 minutes of original post ------------------------------

Does this help? It's a snippet from the page I tried to link to!

VBA CODE:
Function Item_Open() 
    strForm = "IPM.Note.Your Custom Form" 
    Set objFolder = _ 
    Application.ActiveExplorer.CurrentFolder 
    Set objItem = _ 
    objFolder.Items.Add(strForm) 
    objItem.Display 
    Item_Open = False 
End Function 

Presumably if you know the name of the textbox/control/whatever you're trying to populate you could add a few lines like

objItem.tbEmailAddresses.text = "blah" (where blah = a variable/variant containing the addresses?) To save time I'd just add a named cell concatenating the addresses and before doing the above simply say

blah.value = activeworkbook.sheets(i).range("blah").value

Hope this helps a bit/I've understood!


Last edited by Death; 21st September 2010 at 17:19.
  #3  
Unread 22nd September 2010, 01:04
Mhuddles1981's Avatar
Mhuddles1981 Mhuddles1981 is offline
Junior Member
MS Office Version: MS Office 2003
MS Office Skill Level: Can use VBA
 
Join Date: Aug 2010
Location: Townsville
Age: 33
Posts: 77
Posts Per Day: 0.05
My Top Tip Count: 0
Thanks to others: 16
Thanked 1 Time in 1 Post
Reputation: 20 (5) Mhuddles1981 is on a distinguished road
Australia
Default Re: Open Email template with VBA from Excel

------ Register to get rid of these "In Post" ads! ------


I'm new to the outlook code so still trying to get my head around it's object model so what you wrote above just went way over my head.

Can you explain it for me?

------------------------------ posted before receiving a reply after 2 Hours 1 of original post ------------------------------

Hi Death,

I've got a code that works well however I can't seem to populate a user-defined outlook field with a cell value. Here is my code:

VBA CODE:
Sub Inform_IC() 
     
    Dim myOLApp As Object 
    Dim myitem As Object 
     
    mydrive = Worksheets(1).Range("A3") 
    RFileDate = Worksheets(1).Range("B6") 
    MyE_temp = mydrive & "Temp Data\" & Worksheets(1).Range("A5") 
     
    Set myOLApp = CreateObject("Outlook.Application") 
    Set myitem = myOLApp.createitemfromtemplate(MyE_temp) 
    With myitem 
         '.rdate = RFileDate
        .To = "" 
        .display 'or use .send
    End With 
End Sub 

The Rdate is my user-defined field.

Any help is appreciated

Cheers


Last edited by Mhuddles1981; 22nd September 2010 at 01:04.
The Code Cage Advertisment
Advertisement

To stop seeing these ads and get other benefits check This page!

  #4  
Unread 22nd September 2010, 09:14
Death's Avatar
Death Death is offline
Junior Member
MS Office Version: MS Office 2003, 2007
MS Office Skill Level: Some VBA experience
 
Join Date: Sep 2010
Location: Royal Leamington Spa, Warwickshire
Posts: 14
Posts Per Day: 0.01
My Top Tip Count: 0
Thanks to others: 4
Thanked 4 Times in 3 Posts
Reputation: 70 (5) Death will become famous soon enough
Scotland
Default Re: Open Email template with VBA from Excel

------ Register to get rid of these "In Post" ads! ------


Try this:

VBA CODE:
Sub Inform_IC() 
    Dim OLApp, OLItem, OLCustField2Fill, OLCustField2FillName 
     'I'd suggest you use named ranges
     'instead of hardcoding cell references...
     'but I'll roll with it for now...
     'i.e. What if the end user inserts a row/column?
    mydrive = Worksheets(1).Range("A3").Value 'I always add dot-whatever
    RFileDate = Worksheets(1).Range("B6").Value 
    MyE_temp = mydrive & "Temp Data\" & Worksheets(1).Range("A5").Value 
    OLCustField2FillName = "rDate" 'you may want to change this to a worksheet range like the others
    Set OLApp = CreateObject("Outlook.Application") 
    Set OLItem = OLApp.CreateItemFromTemplate(MyE_temp) 
    Set OLCustField2Fill = OLItem.GetInspector.ModifiedFormPages(1).Controls(OLCustField2FillName) 
     'fill
    With OLItem 
        .Subject = "Da-da-da Dummmm" 
        .Body = "Hello world" 
        .Display 
        OLCustField2Fill.Value = "foo" 
    End With 
     'Dead
End Sub 

Reply & Quote Reply


1 members found this post helpful.
The Following User Says Thank You to Death For This Useful Post:
Mhuddles1981 (22nd September 2010)
  #5  
Unread 22nd September 2010, 09:24
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
Administrator
MS Office Version: MS Office 97 - 2013
MS Office Skill Level: Can use most of MS Office
 
Join Date: Aug 2008
Location: Manchester, England
Age: 50
Posts: 11,684
Posts Per Day: 5.03
My Top Tip Count: 11
Thanks to others: 41
Thanked 427 Times in 412 Posts
Reputation: 6454 (187) Simon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond repute
11 Top Tips
Wales
Default Re: Open Email template with VBA from Excel

------ Register to get rid of these "In Post" ads! ------


Death, it's great to see you sharing your knowledge and help, it is unfortunate that we don't allow link posting until after 5 posts but this is purely to try to keep the board clean of spammers - and trust me we've had hundreds of them! - sorry for the inconvienience

As a side note it might be prudent here to point out to the OP this section
VBA CODE:
Sub Inform_IC() 
    Dim OLApp, OLItem, OLCustField2Fill, OLCustField2FillName 
     'I'd suggest you use named ranges
     'instead of hardcoding cell references...
     'but I'll roll with it for now...
     'i.e. What if the end user inserts a row/column?
    mydrive = Worksheets(1).Range("A3").Value 'I always add dot-whatever
a named range would only help if it was dynamically named, i.e instead of simply typing a name in the cell reference box and hitting enter or going to Insert>Names>Define Name adding a name then a range reference like =A1:A100, you should again go to define name but instead use
My Formula:
=OFFSET(Sheet1!$A$1,0,0,COUNTA(Sheet1!$A:$A),1)
this way if a row or cell is added the named range will expand to accommodate it and like wise will shrink to accommodate
__________________
Regards,
Simon Lloyd
Microsoft Office Help

Want to say thanks? then hit this How to say thanks! button in any post you want to thank
If you find one of my posts helpful then hit this one Helpful Answer in the post that helped most!




Last edited by Simon Lloyd; 22nd September 2010 at 09:32.
  #6  
Unread 22nd September 2010, 09:32
Death's Avatar
Death Death is offline
Junior Member
MS Office Version: MS Office 2003, 2007
MS Office Skill Level: Some VBA experience
 
Join Date: Sep 2010
Location: Royal Leamington Spa, Warwickshire
Posts: 14
Posts Per Day: 0.01
My Top Tip Count: 0
Thanks to others: 4
Thanked 4 Times in 3 Posts
Reputation: 70 (5) Death will become famous soon enough
Scotland
Default Re: Open Email template with VBA from Excel

------ Register to get rid of these "In Post" ads! ------


No probs. I'm just glad there isn't one of those "type in what you see" doo-dah's with illegible gibberish that you can hardly read <Death wears shades indoors to fend off the evil migraine inducing corporate lighting... and of course to perve on the secretariat...>

The Code Cage Advertisment
Advertisement
  #7  
Unread 22nd September 2010, 09:37
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
Administrator
MS Office Version: MS Office 97 - 2013
MS Office Skill Level: Can use most of MS Office
 
Join Date: Aug 2008
Location: Manchester, England
Age: 50
Posts: 11,684
Posts Per Day: 5.03
My Top Tip Count: 11
Thanks to others: 41
Thanked 427 Times in 412 Posts
Reputation: 6454 (187) Simon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond repute
11 Top Tips
Wales
Default Re: Open Email template with VBA from Excel

------ Register to get rid of these "In Post" ads! ------


Quote:
Originally Posted by Death View Post

No probs. I'm just glad there isn't one of those "type in what you see" doo-dah's with illegible gibberish that you can hardly read

most bot programs can autofill these now so no good really they just annoy the membership!
Quote:
Originally Posted by Death View Post

<Death wears shades indoors to fend off the evil migraine inducing corporate lighting... and of course to perve on the secretariat...>

Whilst i can't publicly condone the latter part i believe mirrored are best for this task
__________________
Regards,
Simon Lloyd
Microsoft Office Help

Want to say thanks? then hit this How to say thanks! button in any post you want to thank
If you find one of my posts helpful then hit this one Helpful Answer in the post that helped most!



  #8  
Unread 22nd September 2010, 10:26
Death's Avatar
Death Death is offline
Junior Member
MS Office Version: MS Office 2003, 2007
MS Office Skill Level: Some VBA experience
 
Join Date: Sep 2010
Location: Royal Leamington Spa, Warwickshire
Posts: 14
Posts Per Day: 0.01
My Top Tip Count: 0
Thanks to others: 4
Thanked 4 Times in 3 Posts
Reputation: 70 (5) Death will become famous soon enough
Scotland
Default Re: Open Email template with VBA from Excel

------ Register to get rid of these "In Post" ads! ------


Yup, that's what I usually do when using a (>1 cell) range - using offset/counta/sum a variation of that is great for charts and pivot tables too; if you're revisiting the workbook and building up the months/weeks/days whatever.

The indirect function coupled with a list of worksheet names and counta's also provides a novel (if not actually all that practical!) way of establishing how many rows/columns have been used on any given sheet - but watch out for blank rows/columns... see attachment. It may be possible to incorporate this into a named range without vba but I'm not sure, haven't tried!
Attached Files To view attachments in this forum your post count must be 2 or greater. You currently have 0 posts.

The Following User Says Thank You to Death For This Useful Post:
selva (18th January 2011)
  #9  
Unread 23rd September 2010, 00:00
Mhuddles1981's Avatar
Mhuddles1981 Mhuddles1981 is offline
Junior Member
MS Office Version: MS Office 2003
MS Office Skill Level: Can use VBA
 
Join Date: Aug 2010
Location: Townsville
Age: 33
Posts: 77
Posts Per Day: 0.05
My Top Tip Count: 0
Thanks to others: 16
Thanked 1 Time in 1 Post
Reputation: 20 (5) Mhuddles1981 is on a distinguished road
Australia
Default Re: Open Email template with VBA from Excel

------ Register to get rid of these "In Post" ads! ------


Thanks Deeath (I never thought i would say that and mean it ),

The code worked like a charm.

I really appreciate your help.

Cheers

The Following User Says Thank You to Mhuddles1981 For This Useful Post:
selva (18th January 2011)
The Code Cage Advertisment
Advertisement
  #10  
Unread 18th January 2011, 06:43
selva's Avatar
selva selva is offline
Junior Member
MS Office Version: MS Office 2007
MS Office Skill Level: Can use VBA
 
Join Date: Jan 2011
Location: australia
Posts: 1
Posts Per Day: 0.00
My Top Tip Count: 0
Thanks to others: 2
Thanked 0 Times in 0 Posts
Reputation: 10 (0) selva is on a distinguished road
Default Re: Open Email template with VBA from Excel

------ Register to get rid of these "In Post" ads! ------


Thanks for the help

The Code Cage Advertisment
Advertisement
New Reply
The Code Cage at Facebookhe Code Cage at Twitter


Tags
email, excel, open, template, vba

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

The Code Cage Affilliates



http://www.thecodecage.com/forumz tested by McAfee Security http://www.thecodecage.com/forumz tested by McAfee Security

All times are GMT +1. The time now is 08:22.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Template-Modifications by TMS
No part of this board, functionality or creatives may be copied or reproduced either in part or full without the express permission of The Code Cage Team.
Copyright ©2008 - , Simon lloyd.
We are not associated with nor employed by Microsoft in any way, we simply provide resources!
All MS office icons are registered trademarks of the application they represent and are used with permission from Microsoft
UA-8135493-1
Cultural Forum | Study at Malaysian University