+ Reply to Thread
Results 1 to 28 of 28

Macro that will create & send standard email

  1. #1
    Forum Contributor
    Join Date
    05-14-2007
    Posts
    117

    Macro that will create & send standard email

    Hello Everyone,

    Im wondering if anyoune can help me write some code please?
    I am creating a service log, that will hopefully do sum great things!!

    I would like a macro that recognises the cell colour in column F if it is yellow i would like a standard email to be created & sent to the corresponding customer email address in column D. is this even possible??

    Many Thanks

    Jamie.c
    Attached Files Attached Files
    Last edited by jamie.c; 02-13-2009 at 05:56 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Macro that will create & send standard email

    Are you using Conditional Formatting to get the cell colour?
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Contributor
    Join Date
    05-14-2007
    Posts
    117

    Re: Macro that will create & send standard email

    Hello Roy

    Thanks for your reply, yeah im in the process of doing it that way, but if thats not going to help with the macro im open to your ideas??

    Thanks in advance

    Jamiec

  4. #4
    Forum Contributor
    Join Date
    05-14-2007
    Posts
    117

    Re: Macro that will create & send standard email

    ----------bump--------------

  5. #5
    Forum Contributor
    Join Date
    05-14-2007
    Posts
    117

    Question Re: Macro that will create & send standard email

    Can Anyone help please?

    Many Thanks

    Jamiec

  6. #6
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Macro that will create & send standard email

    hi Jamie,

    You may find useful info on the below links:
    http://www.rondebruin.nl/sendmail.htm
    especially on this link which is near the bottom of the above page...
    http://www.rondebruin.nl/mail/change.htm

    Ron's mention of conditional formatting is quite relevant here because conditional formatting relies on a condition being met (eg a cell value changing) & it is likely that the same logic can be applied within a macro.

    hth
    Rob
    Rob Brockett
    Kiwi in the UK
    Always learning & the best way to learn is to experience...

  7. #7
    Forum Contributor
    Join Date
    05-14-2007
    Posts
    117

    Question Re: Macro that will create & send standard email

    Thanks for your response Rob, Ive looked at the examples and I haven got enough knowledge to modify those to suit my worksheet, can anyone help please??

    Many thanks in advance

    Jamiec

  8. #8
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Macro that will create & send standard email

    hi Jamie,

    Apologies for the slow response - I've been away for the weekend & now that it is time to go back to work I may be slow again...

    Hopefully, if I'm too slow someone else will jump in. Can you please attach an example file in the Excel 2003 (.xls) format?

    Rob

  9. #9
    Forum Contributor
    Join Date
    05-14-2007
    Posts
    117

    Re: Macro that will create & send standard email

    Hi rob, My opologies to for being slow!

    Thanks for your response,

    Ill do a swap with you and ill move out to new zealand looks a beautiful place to live!!!

    Jamiec
    Attached Files Attached Files

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Macro that will create & send standard email

    Hello jamie.c,

    That was some challenge! I am awarding you points for this one. Columns "F" and "G" have conditional formatting applied. If the service date is 28 to 0 days before today, it is colored yellow. If today is 1 day or more past the service date, it is colored red.

    Emails are sent when the command button "Send Emails" on Sheet1 is clicked. After an email is sent, the macro adds a Comment to the cell with the data and time the email was sent. If an error occurs when sending a email, the macro will stop sending emails until the error is corrected.

    Conditional Formatting Formulae
    Please Login or Register  to view this content.
    Send Emails Macro
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  11. #11
    Forum Contributor
    Join Date
    05-14-2007
    Posts
    117

    Talking Re: Macro that will create & send standard email

    That is perfect!!!!!

    Thankyou so much!!

    Just a quick Question though, what email is that set up to send at the moment? can it select a signature as a template?

    And how easy would it be to add some code that will automatically print a letter off that will add the relevant company name in to it, so a copy can be posted? is that easy or even possible??

    Many many thanks

    Jamiec

  12. #12
    Forum Contributor
    Join Date
    05-14-2007
    Posts
    117

    Question Re: Macro that will create & send standard email

    ---------bump----------

  13. #13
    Forum Contributor
    Join Date
    05-14-2007
    Posts
    117

    Question Re: Macro that will create & send standard email

    Can anyone help please?

  14. #14
    Forum Contributor
    Join Date
    05-14-2007
    Posts
    117

    Question Re: Macro that will create & send standard email

    Hello All!

    Just wondering if anyone out there knows if it is possible for the macro that Leith kindly wrote for me would be able to select a certain signature as the template email?

    Any Help or advice would be much appreciated

    Thanks in Advance

    Jamiec

  15. #15
    Forum Contributor
    Join Date
    08-21-2008
    Location
    Hamilton, New Zealand
    MS-Off Ver
    Office 2007
    Posts
    255

    Re: Macro that will create & send standard email


  16. #16
    Forum Contributor
    Join Date
    05-14-2007
    Posts
    117

    Re: Macro that will create & send standard email

    Hello All

    I have A some code that Leith kindly wrote for me some time ago, I never got round to finishing the project, but as I picked it back up and had a play with it I realized I didnt work as it did when I first recieved it. when I press the "Send Email" Button now it comes up with "Error - emails stopped active X component cant create object" Can anyone help me out please n point me in the right direction?

    Many Thanks

    jamie.c

  17. #17
    Forum Contributor
    Join Date
    05-14-2007
    Posts
    117

    Re: Macro that will create & send standard email

    Hello All,

    It has been a while since I started this project, and it never got finished before, so I have picked it back up to have a play with it, and it seems not to work now!!!!!!! I know it did before, can anyone help me out please?? When I press the "send Email" Button It comes up with " Error - Emails stopped Active X Component cant create object" Can anyone help please?

    Many Thanks

    Jamie.c

  18. #18
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Macro that will create & send standard email

    hi Jamie,

    Can you please post your latest version of your file for us to look at?

    Longshot questions (without investigating the error):
    Have you changed the name of "Sheet1"?
    Does the computer you are using have MS Outlook installed?


    Rob

  19. #19
    Forum Contributor
    Join Date
    05-14-2007
    Posts
    117

    Re: Macro that will create & send standard email

    Good Morning Rob,

    Many thanks for your reply, Its very strange, It worked great the first time I used it then it got put to one side for a while, now It just comes up with the error, even when I go back to the original posted back to me. I have definately got Ms Outlook & I havent altered anything of the original! I cannot think what it could be

    Thanks Again, look forward to your response

    Jamie.c
    Attached Files Attached Files

  20. #20
    Forum Contributor
    Join Date
    05-14-2007
    Posts
    117

    Re: Macro that will create & send standard email

    ---------BUMP---------

    Any Help would be much appreciated

    Thanks In advance

  21. #21
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Macro that will create & send standard email

    Hello jamie.c,


    I downloaded the workbook and it runs fine on my machine. I am running Excel 2003 under Windows XP. Has your computer software changed since the last time the program ran correctly? Are you running this on single computer or on a network?

  22. #22
    Forum Contributor
    Join Date
    05-14-2007
    Posts
    117

    Re: Macro that will create & send standard email

    Good afternoon Leith,

    Thank you so much for your reply, much appreciated!

    Its strange my computor/software has not changed, but the document is on a server, will that make a difference?

    Thanks again

    Jamie.c

  23. #23
    Forum Contributor
    Join Date
    05-14-2007
    Posts
    117

    Re: Macro that will create & send standard email

    On Error GoTo ErrorOut

    Set olApp = CreateObject("Outlook.Application")

    Set Wks = Worksheets("Sheet1")
    Set Rng = Wks.Range("F4")
    Set RngEnd = Wks.Cells(Wks.Rows.Count, Rng.Column).End(xlUp)
    Set RngEnd = IIf(RngEnd.Row < Rng.Row, Rng, RngEnd)
    Set Rng = Wks.Range(Rng, RngEnd).Resize(Columnsize:=2)

    Application.ScreenUpdating = False

    For Each Cell In Rng
    CellColor = xlColorIndexNone
    With Cell.FormatConditions
    Cell.Select
    Condition1 = Evaluate(.Item(1).Formula1)
    If Condition1 = True Then CellColor = .Item(1).Interior.ColorIndex
    Condition2 = Evaluate(.Item(2).Formula1)
    If Condition2 = True Then CellColor = .Item(2).Interior.ColorIndex
    End With
    'Yellow means due in 4 weeks. Comment is holds date time stamp for email.
    If CellColor = 6 And (Cell.Comment Is Nothing) Then
    SendTo = Wks.Cells(Cell.Row, "D").Text
    Set olEmail = olApp.CreateItem(0)
    With olEmail
    .To = SendTo
    .Subject = "Service Schedule"
    .Body = "Email Test." 'Include your message between the quotes
    .Send
    Cell.AddComment "Email sent " & Now()
    End With
    End If
    Next Cell

    ErrorOut:
    Application.ScreenUpdating = True

    If Err <> 0 Then
    MsgBox "ERROR - Emails Stopped" & vbCrLf & Err.Description & vbCrLf & SendTo
    Err.Clear
    On Error GoTo 0
    End If

    'Terminate the Outlook
    olApp.Quit

    'Free objects in memory
    Set olApp = Nothing
    Set olEmail = Nothing

    End Sub
    If this helps, the text in green is highlighted on the debug

    Thanks again

    Jamie.c
    Last edited by jamie.c; 06-08-2009 at 11:36 AM.

  24. #24
    Forum Contributor
    Join Date
    05-14-2007
    Posts
    117

    Re: Macro that will create & send standard email

    --------bump----------

  25. #25
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Macro that will create & send standard email

    Hello jamie.c,

    I don't know why you would receive the error "Component can't create object" because the object has already been created. At this point, the macro is closing Outlook, not creating it. Have you checked that you have been granted the proper access rights to create and destroy objects on your server?

  26. #26
    Forum Contributor
    Join Date
    05-14-2007
    Posts
    117

    Re: Macro that will create & send standard email

    Hello Leith,

    Thank you for your reply,

    I checked my email & server security settings, I enabled some that I thought may work but it still does the same, my outlook is 2007, that may have changed from the original, would that make a difference?

    Is there a different approch that I could take to acheive the same out come?

    Any help would be much appreciated

    Jamie.c

  27. #27
    Forum Contributor
    Join Date
    02-03-2009
    Location
    Doha, Qatar
    MS-Off Ver
    Excel 2010
    Posts
    132

    Re: Macro that will create & send standard email

    Quote Originally Posted by Leith Ross View Post
    Hello jamie.c,

    That was some challenge! I am awarding you points for this one. Columns "F" and "G" have conditional formatting applied. If the service date is 28 to 0 days before today, it is colored yellow. If today is 1 day or more past the service date, it is colored red.

    Emails are sent when the command button "Send Emails" on Sheet1 is clicked. After an email is sent, the macro adds a Comment to the cell with the data and time the email was sent. If an error occurs when sending a email, the macro will stop sending emails until the error is corrected.

    Conditional Formatting Formulae
    Please Login or Register  to view this content.
    Send Emails Macro
    Please Login or Register  to view this content.
    Dear Leith,
    I tried using this sheet by modifying only data but when i try to click "Send email",,my outlook only closes , y is this happening.
    I am using all 2007 versions
    Thanks
    Max

  28. #28
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Macro that will create & send standard email

    Hello maximpinto,

    Since I don't have Office 2007, I can't really answer your question as to why. There were at lot of changes made in Office 2007. This is first time Microsoft broke with its tradition of backward compatibility. The code works fine in Office 2000 and 2003, but evidently something has changed in 2007. I suspect it is related to changes in Outlook.

    You may want to defer your questions to either Sue Mosher or Ron De Bruin. Sue is the Outlook guru and Ron the email man. You can post on either or both of these Microsoft sites if you want to reach them.

    http://groups.google.com/group/micro...el.programming
    http://groups.google.com/group/micro...ok.program_vba

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1