-
Outlook , Send message with VBA
Hi all,
I saw a sample code in "http://www.freevbcode.com/ShowCode.asp?ID=159" that shows how to create and send a email programmatically.
What I want to know is if I prefer to open Outlook first with ".DISPLAY (TRue)" and then let user decide to send or not clicking SEND button, how can I know if the email was sent ? I tried SENT property but got error with code below :
Code:
Sub outlook()
Dim oout As Object
Dim omsg As Object
Set oout = CreateObject("Outlook.Application")
Set omsg = oout.CreateItem(0)
With omsg
.To = "John@acme.com.br"
.CC = ""
.BCC = ""
.Subject = "Teste Objeto Outlook no Macro Excel"
.Body = "Macro Excel Outlook!"
.Display (True) // Wait User edit and click SEND button or not
End With
// I got Run time error ... Item moved or removed
If omsg.Sent Then
MsgBox (" Sent ")
Else
MsgBox (" Not Send ! ")
End If
Set oout = Nothing
Set omsg = Nothing
End Sub
I will appreciate any help
Hu
-
What was the error that you got?
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
Please use [Code]your code goes in here[/Code] tags when posting code.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
Modifications Required For VB6 Apps To Work On Vista
-
Outlook , Send message with VBA
Hi HACK,
When I run the macro , it opens Outlook then after click Send button I got run time error "Item moved or removed" on omsg.SENT property.
Tia,
Hu
-
That is telling you the message has been sent, and you are trying to display something that isn't there.
I don't see any code, in what you published, that does the message sending. Is there are separate part of your program that you didn't post?
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
Please use [Code]your code goes in here[/Code] tags when posting code.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
Modifications Required For VB6 Apps To Work On Vista
-
Outlook , Send message with VBA
Hi Hack,
 Originally Posted by Hack
That is telling you the message has been sent, and you are trying to display something that isn't there.
Of course ! AFTER CLICK SEND button the message was sent ... Sorry I didn´t realize this before. But what I would like to know is : Programmatically is there any property or method or code that confirm or not message sending , after user click SEND button ?
 Originally Posted by Hack
I don't see any code, in what you published, that does the message sending. Is there are separate part of your program that you didn't post?
No, I posted all of it.
-
Try this
Code:
Sub outlook()
Dim oout As Object
Dim omsg As Object
On Error GoTo ErrTrap '<============= add this line
Set oout = CreateObject("Outlook.Application")
Set omsg = oout.CreateItem(0)
With omsg
.To = "John@acme.com.br"
.CC = ""
.BCC = ""
.Subject = "Teste Objeto Outlook no Macro Excel"
.Body = "Macro Excel Outlook!"
.Display (True) // Wait User edit and click SEND button or not
End With
// I got Run time error ... Item moved or removed
If omsg.Sent Then
MsgBox (" Sent ")
Else
MsgBox (" Not Send ! ")
End If
Set oout = Nothing
Set omsg = Nothing
Msgbox "Message Sent Successfully" '<====== add this line
Exit Sub '<======= add this line
ErrTrap: '<======== add this and the line below
Msgbox Err.Number & " " & Err.Description & " message not sent because of error"
End Sub
If your code receives no errors the first message box will be displayed. If there is an error sending it, the second msgbox will be displayed.
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
Please use [Code]your code goes in here[/Code] tags when posting code.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
Modifications Required For VB6 Apps To Work On Vista
-
 Originally Posted by Hack
Try this
Code:
Sub outlook()
Dim oout As Object
Dim omsg As Object
On Error GoTo ErrTrap '<============= add this line
Set oout = CreateObject("Outlook.Application")
Set omsg = oout.CreateItem(0)
With omsg
.To = "John@acme.com.br"
.CC = ""
.BCC = ""
.Subject = "Teste Objeto Outlook no Macro Excel"
.Body = "Macro Excel Outlook!"
.Display (True) // Wait User edit and click SEND button or not
End With
// I got Run time error ... Item moved or removed
If omsg.Sent Then
MsgBox (" Sent ")
Else
MsgBox (" Not Send ! ")
End If
Set oout = Nothing
Set omsg = Nothing
Msgbox "Message Sent Successfully" '<====== add this line
Exit Sub '<======= add this line
ErrTrap: '<======== add this and the line below
Msgbox Err.Number & " " & Err.Description & " message not sent because of error"
End Sub
If your code receives no errors the first message box will be displayed. If there is an error sending it, the second msgbox will be displayed.
Hi Hack,
I got "-2147221238.Item moved or removed, message not sent because of error".
To you understand better my problem : I´m a XHarbour guy and have a program that setup email info as To, Subject, Body, Attach, etc, and opens Outlook. The user could change or not the info and click SEND button. All this works fine. But now I need some mean that states if the user really has sent the message (clicked or not SEND button) for control purposes.
Tia,
Hu
-
What is the code in your "SEND" button?
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
Please use [Code]your code goes in here[/Code] tags when posting code.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
Modifications Required For VB6 Apps To Work On Vista
-
Outlook , Send message with VBA
 Originally Posted by Hack
What is the code in your "SEND" button?
I appreciate your concern and sorry if I´m not clear :
In my XHarbour code I can create OLE objects with almost same VBA syntax.
So when I need some simple WIN application in XHarbour what I do is test VBA code as macro in Excel or Outlook and if works translate it to XHarbour OLE object. In this case my XHarbour code creates Outlook object and a email then opens the inspector for user to confirm or change some info and then click SEND or not. Until now it works well but I have no way to know what user really did. Mainly I must know if the message was sent.
In other words in my XHarbour code there is a option that opens Outlook message Inspector with a email just waiting user action and after user close Outlook returns to XHarbour code. The problem is : before Outlook is closed there is any mean to get a info if message was sent or not ?
Thanks,
Hu
Similar Threads
-
By paulnf in forum VB Classic
Replies: 7
Last Post: 06-27-2007, 05:11 PM
-
By Olivier Lhomme in forum Enterprise
Replies: 0
Last Post: 02-27-2002, 04:12 AM
-
By Devx Exchange in forum Enterprise
Replies: 0
Last Post: 05-24-2001, 12:21 PM
-
Replies: 0
Last Post: 11-27-2000, 04:41 AM
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
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks