|
-
Jan 21st, 2005, 01:48 PM
#1
Thread Starter
New Member
Automated Transfer/Reply e-mail (VB, MAPI, Outlook)
Hi everybody,
I'm very new to VB programming within Office Apps (though I have heavy Java/C/C++ background).
I want to create a macro that will process a stored sent mail (i.e. the currently selected mail in Outlook) by modifying some of its attached documents, its subject and its body, and put the new e-mail either in the Draft or Outgoing mail box.
I saw a lot of resources here on the forums but none giving a short start to this kind of task I am asking for (still looking throughout the forums, though).
Thanks for any help !
-
Jan 21st, 2005, 01:53 PM
#2
Re: Automated Transfer/Reply e-mail (VB, MAPI, Outlook)
I have a module specifically for working with Outlook. It's only got 1 function but it may help you out to get started.
VB Code:
Option Explicit
'
' References:
' - Microsoft Outlook 9.0 Object Library (msoutl9.olb)
'
Sub SendEmail()
Dim objOutlook As Outlook.Application
Dim objMailItem As Outlook.MailItem
'
Set objOutlook = New Outlook.Application
Set objMailItem = objOutlook.CreateItem(0)
'
With objMailItem
.To = "To"
.CC = "CC To"
.Subject = "Subject"
.HTMLBody = "Body in the form of HTML"
.Send
End With
'
End Sub
Nobody knows what software they want until after you've delivered what they originally asked for.
Don't solve problems which don't exist.
"If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)
2 idiots don't make a genius.
-
Jan 21st, 2005, 02:14 PM
#3
Thread Starter
New Member
Re: Automated Transfer/Reply e-mail (VB, MAPI, Outlook)
Thanks for the kickstart.
Now, I guess it's a matter of :
1. recover the currently selected e-mail (ideally, I would have to make a macro of this, operable with a toolbar button from Outlook)
2. move it to a desired folder and/or send it
-
Jan 21st, 2005, 02:27 PM
#4
Re: Automated Transfer/Reply e-mail (VB, MAPI, Outlook)
Are you wanting to do this in Outlook VBA or automate Outlook using VB?
To get the currently selected item in Outlook using either method use the
Outlook.Selection object. Something like this...
VB Code:
Dim oExp As Outlook.Explorer
Dim oSel As Outlook.Selection
Set oExp = Outlook.ActiveExplorer
Set oSel = oExp.Selection
Ps, Dave you may want to set the .BodyFormat = olFormatHTML first before
specifing the body content. 
Pss, if you do this in Outlook VBA you can avoid the "Do you want to send
this emai" Security prompt.
HTH
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 21st, 2005, 02:36 PM
#5
Re: Automated Transfer/Reply e-mail (VB, MAPI, Outlook)
 Originally Posted by RobDog888
Ps, Dave you may want to set the .BodyFormat = olFormatHTML first before specifing the body content. 
[/color]
Then do I still use the method?
Nobody knows what software they want until after you've delivered what they originally asked for.
Don't solve problems which don't exist.
"If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)
2 idiots don't make a genius.
-
Jan 21st, 2005, 03:23 PM
#6
Re: Automated Transfer/Reply e-mail (VB, MAPI, Outlook)
Yes, what the format does is determines the standard used to display the text of the message.
VB Code:
Option Explicit
'
' References:
' - Microsoft Outlook 9.0 Object Library (msoutl9.olb)
'
Sub SendEmail()
Dim objOutlook As Outlook.Application
Dim objMailItem As Outlook.MailItem
'
Set objOutlook = New Outlook.Application
Set objMailItem = objOutlook.CreateItem(0)
'
With objMailItem
.To = "To"
.CC = "CC To"
.Subject = "Subject"
.BodyFormat = olFormatHTML
.HTMLBody = "Body in the form of HTML"
.Send
End With
'
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 21st, 2005, 06:44 PM
#7
Thread Starter
New Member
Re: Automated Transfer/Reply e-mail (VB, MAPI, Outlook)
 Originally Posted by RobDog888
Are you wanting to do this in Outlook VBA or automate Outlook using VB?
I'm doing it under Outlook VBA
 Originally Posted by RobDog888
To get the currently selected item in Outlook using either method use the
Outlook.Selection object. Something like this...
VB Code:
Dim oExp As Outlook.Explorer
Dim oSel As Outlook.Selection
Set oExp = Outlook.ActiveExplorer
Set oSel = oExp.Selection
Alright. But then, Outlook.Selection object is a collection of any type of Outlook elements.
How do I know it is an e-mail (codewise) ? Do I have to cast it somehow ?
And also : how do I get the element itself rather than the Selection (=the collection object) ?
-
Jan 21st, 2005, 09:17 PM
#8
Re: Automated Transfer/Reply e-mail (VB, MAPI, Outlook)
This code works in either VB or VBA.
VB Code:
'If using in VB add a reference to MS Outlook xx.0 Object Library
Private Sub Command1_Click()
Dim oExp As Outlook.Explorer
Dim oSel As Outlook.Selection
Dim oFolder As Outlook.MAPIFolder
Dim sType As String
Set oExp = Outlook.ActiveExplorer
Set oFolder = oExp.CurrentFolder
Set oSel = oExp.Selection
Select Case oSel.Item(1).Class
Case olTask
sType = "Task"
Case olMail
sType = "Email"
Case olContact
sType = "Contact"
Case olJournal
sType = "Journal"
Case olNote
sType = "Note"
Case olAppointment
sType = "Calendar"
Case Else
sType = "Unknown Type!"
End Select
MsgBox sType & " Selected!"
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 22nd, 2005, 06:33 AM
#9
Thread Starter
New Member
Re: Automated Transfer/Reply e-mail (VB, MAPI, Outlook)
Thanks a lot. I made huge steps in a few hours.
There are some details, though, that I wish to change :
Using this code as an Outlook macro, it would execute a new Outlook process each time it is executed. Is there any way to keep the execution within the running Outlook process ?
-
Jan 22nd, 2005, 01:58 PM
#10
Re: Automated Transfer/Reply e-mail (VB, MAPI, Outlook)
How do your code look because the code I posted shouldn't be creating a new Outlook session?
Last edited by RobDog888; Feb 1st, 2005 at 11:49 AM.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|