Hi,
I have the following code, and while it is working, but I would like to tweak it around to suit my needs:
What I want:Private Sub EmailtoTeam_Click() ' This example sends the last saved version of the Activeworkbook object . Dim OutApp As Object Dim OutMail As Object Set OutApp = CreateObject("Outlook.Application") Set OutMail = OutApp.CreateItem(0) On Error Resume Next ' Change the mail address and subject in the macro before you run it. With OutMail .To = "testabc@gmail.com" .CC = "" .BCC = "" .Subject = "test" .Body = "Hello World!" .Attachments.Add ActiveWorkbook.FullName .Send End With On Error GoTo 0 Set OutMail = Nothing Set OutApp = Nothing End Sub
Have the macro open up an instance of Outlook and manually fill in what goes in the body. The recipient's email address and the subject lines can use what's in the code above.
The code will send the current active workbook out as an attachment, and I would like to keep this feature.
Is this doable via a macro?
Thanks
Last edited by Lifeseeker; 02-10-2012 at 02:42 PM.
Anybody able to assist on this one?
Thanks
Any one able to assist?
The current code opens outlook and passes what's in the code to corresponding fields in Outlook.
However, what I would like it to work is:
1) Open outlook and fill the corresponding fields in Outlook
2) have user manually hit "Send" button in Outlook.
3) have the macro close that instance of Outlook.
Is this doable?
ThanksPrivate Sub EmailtoTeam_Click() ' This example sends the last saved version of the Activeworkbook object . Dim OutApp As Object Dim OutMail As Object Dim strBody As String Shell ("Outlook") Set OutApp = CreateObject("Outlook.Application") Set OutMail = OutApp.CreateItem(1) strBody = "Hi" & vbNewLine & vbNewLine & _ "I have updated the tracking spreadsheet" & vbNewLine & vbNewLine & _ "Please let me know if you have any questions." & vbNewLine & vbNewLine & _ "Cheers!" On Error Resume Next ' Change the mail address and subject in the macro before you run it. With OutMail .To = "test@gmail.com" .CC = "" .BCC = "" .Subject = "Tracking sheet updated" .Body = strBody End With On Error GoTo 0 Set OutMail = Nothing Set OutApp = Nothing End Sub
You would need to change
to.Sendto pop the email up for the user..Display
I would not recommend quitting Outlook as you don't know whether it was already opened by the user.
Good luck.
Wow nice! That's an easy fix.
When it opens the Outlook, it actually opens the "Appointment" window?
Is there any way to have it open the "Message" window with email signatures and everything?
Thanks
Private Sub EmailtoTeam_Click() ' This example sends the last saved version of the Activeworkbook object . Dim OutApp As Object Dim OutMail As Object Dim strBody As String Shell ("Outlook") Set OutApp = CreateObject("Outlook.Application") Set OutMail = OutApp.CreateItem(1) strBody = "Hi" & vbNewLine & vbNewLine & _ "I have updated the tracking spreadsheet" & vbNewLine & vbNewLine & _ "Please let me know if you have any questions." & vbNewLine & vbNewLine & _ "Cheers!" On Error Resume Next ' Change the mail address and subject in the macro before you run it. With OutMail .To = "test" .CC = "" .BCC = "" .Subject = "Tracking sheet updated" .Body = strBody .display End With On Error GoTo 0 Set OutMail = Nothing Set OutApp = Nothing End Sub
That is because you created an appointment item! This line
shoudl beSet OutMail = OutApp.CreateItem(1)
Set OutMail = OutApp.CreateItem(0)
Good luck.
wow nice, I wasn't aware of that.
so I guess
by default creates appointments?Set OutApp = CreateObject("Outlook.Application") Set OutMail = OutApp.CreateItem(0)
Thanks
oh and.....I guess the code just creates a new instance of Outlook and from there displays the email window.
What if....the Outlook is already open? I don't want it to create a new instance of Outlook if the Outlook is already running. In this case, is it possible to have it display an new email window from existing Outlook application?
It will use an open outlook instance.
The 0 means mail item, 1 means appointment.
Good luck.
Hi,
I am wondering if I can put a check in the code and have it first check to see if the Outlook is already open. If the Outlook is already running, then just open up a new email window from it and execute the rest of the code. If Outlook is not yet running, first start Outlook and from it open up an "Email" window and execute the rest of the code.
Is this possible?
THanks
Is it not doing that anyway?
Good luck.
Sorry should have been more clearer:
Currently, if the Outlook is already running, while the code does open the email window, it has to open a new instance of the Outlook along with it. I think this is because the code itself actually creates a new Outlook object and from it creates an appointment type of "0"?
So, I guess the more times users click on the button, the more instances of Outlook are created, and this might be a problem down the road now as I see it. (users probably just want to click on it once and if the Outlook is already running, open the appointment type of 0 instead of creating a new Outlook object). (Typically, users will have both Excel and Outlook running at the same time here...)
Do you have any suggestions on this?
Thanks
Ah, I missed the fact you have
in your code for some reason. Remove that.Shell ("Outlook")
Good luck.
Nice!
Yeah, I believe I added that shell statement initially because I wasn't understanding how the code creates the Outlook as an object, but thank you and it's working like a charm.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks