ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[µo°Ý] ¨S¦³©w¸q³o­Ósub©Îfunction

[µo°Ý] ¨S¦³©w¸q³o­Ósub©Îfunction

¦U¦ì¤j¤j¦n¡G

³Ìªñ¦b³]©wExcelªí®æ¥ÎVBA Email¥X¥h¡A
¥H¤Uµ{¦¡½X­ì¥»³]©w¦n¤F¡A¤@¤Á¥¿±`¥i¥Î¡C
¦]¬°±N¤£¬ÛÃöªº¨ä¥L¼Ò²Õ§R°£«á¡A³o­Ó¼Ò²Õ°õ¦æ®É«o¥X²{¡u¨S¦³©w¸q³o­Ósub©Îfunction¡v¡A
µM«á¿ù»~°T®§°±¦bSub CDO_TEST_OK()
¦ÓRangetoHTML¥X²{¤Ï¥Õ¡A
µ{¦¡½X¦p¤U¡A½Ð¦U¦ì¤j¤jÀ°À°¦£¡AÁÂÁÂ~~
  1. Sub CDO_TEST_OK()


  2. Dim objCDO As Object
  3. Dim strCfg As String
  4. Set objCDO = CreateObject("CDO.Message")
  5. strCfg = "http://schemas.microsoft.com/cdo/configuration/"

  6. With objCDO

  7. '.Sender = ""   '

  8. .From = "[email protected]"  '±H¥óªÌ
  9. .To = "[email protected]"   '±Hµ¹½Ö

  10. '.Fields("urn:schemas:mailheader:X-Priority") = 1 ' Priority = PriorityUrgent °ªÀu¥ý¶¶§Ç
  11. '.Fields("urn:schemas:mailheader:return-receipt-to") = "" ' ­n¨DŪ¨ú¦^±ø
  12. ' .Fields("urn:schemas:httpmail:importance") = 2 ' Importance = High
  13. ' .Fields("urn:schemas:httpmail:priority") = 1 ' Priority = PriorityUrgent

  14. .Fields.Update ' §ó·sÄæ¦ì
  15. .Subject = "Salary " & Range("A8") & "-" & Range("C8") '¥D¦®


  16. '.TextBody = "ORZ" ' Text ¤å¦r®æ¦¡«H¥ó¤º®e
  17. ' ©Î HTML ºô­¶®æ¦¡«H¥ó¤º®e
  18. .HTMLBody = "<HTML>" & _
  19. "<BODY>" & _
  20. "<table border=""1"" width=""100%"">" & _
  21. "<tr><td>I</td><td>am</td><td>Hammer</td><td>!</td></tr>" & _
  22. "<tr><td>Who</td><td>r</td><td>u</td><td>?</td></tr>" & _
  23. "</table>" & _
  24. "</BODY>" & _
  25. "</HTML>"
  26. .HTMLBody = RangetoHTML(Range("A1:J31")) '¶l¥ó¤º¤å(¬°EXCELªºªí®æ½d³ò)½Ð¨Ì»Ý¨D­×§ï

  27. '.AddAttachment "C:\AttFile.zip" ' ªþ¥[ÀÉ®×
  28. '.CC = "°Æ¥»@yahoo.com.tw" ' °Æ¥»
  29. '.BCC = "±K¥ó°Æ¥»@hotmail.com.tw" ' ±K¥ó°Æ¥»
  30. .Configuration(strCfg & "sendusing") = 2 ' Sendusing = SendUsingPort

  31. .Configuration(strCfg & "smtpserver") = "xxxs.com.tw" ' SMTP Server

  32. '.Configuration(strCfg & "smtpserver") = "msa.hinet.net" ' SMTP Server


  33. ' .Configuration(strCfg & "smtpserverport") = 25 ' SMTP Server Port ( ¹w³]§Y¬° 25 )
  34. ' SMTP Server ¦p»Ýµn¿ý , «h»Ý³]©w UserName / Password
  35. ' .Configuration(strCfg & "sendusername") = "UserName" ' Send User Name
  36. ' .Configuration(strCfg & "sendpassword") = "Password" ' Send Password
  37. .Configuration.Fields.Update ' §ó·s (Äæ¦ì) ²ÕºA
  38. ' .DSNOptions = 4 ' ¦^¶Ç«H¥ó¶Ç°eª¬ºA
  39. ' cdoDSNDefault = 0 , DSN commands are issued.
  40. ' cdoDSNDelay = 8 , Return a DSN if delivery is delayed.
  41. ' cdoDSNFailure = 2 , Return a DSN if delivery fails.
  42. ' cdoDSNNever = 1 , No DSNs are issued.
  43. ' cdoDSNSuccess = 4 , Return a DSN if delivery succeeds.
  44. ' cdoDSNSuccessFailOrDelay = 14 ,Return a DSN if delivery succeeds, fails, or is delayed.
  45. .Send ' ¶Ç°e


  46. End With
  47. Set objCDO = Nothing


  48. End Sub
½Æ»s¥N½X

.HTMLBody = RangetoHTML(Range("A1:J31")) ¦¹¦C¿ù»~

±N FUNCTION RangetoHTML ¶K¦^¨Ó
{...} ªí¥Ü»Ý­n¥Î CTRL+SHIFT+ENTER ¤TÁä¿é¤J¤½¦¡

TOP

¦^´_ 2# ML089

ÁÂÁÂML089¤j¤j¡A
µ{¦¡¥¿±`¥i¥H°õ¦æ¤F¡AÁÂÁÂ
    :D

TOP

¦^´_ 2# ML089

ML089¤j¤j¡G

­è­è¦bµ{¦¡½X³Ì«á­±¥[¤W
Function RangetoHTML(rng As Range)
End Function

µ{¦¡¥i¥¿±`°õ¦æ¨Ã±H°e¶l¥ó¡A
¦ý¬O¶l¥ó¤º¤å¬OªÅ¥Õ¡A¤£·|°õ¦æ¥H¤Uµ{¦¡½X:
.HTMLBody = RangetoHTML(Range("A1:J31"))

ÁÂÁÂ~

TOP

¥»©«³Ì«á¥Ñ c_c_lai ©ó 2016-3-16 12:51 ½s¿è

¦^´_ 4# takeshilin88
¸Õ¸Õ¬Ý
  1. Function RangetoHTML(rng As Range)
  2.     Dim rng2 As Range, txt As String
  3.    
  4.     For Each rng2 In rng
  5.         If rng2 <> "" Then
  6.             txt = txt & " " & rng2.Text
  7.         End If
  8.     Next
  9.     RangetoHTML = txt
  10. End Function
½Æ»s¥N½X

TOP

¦^´_ 4# takeshilin88
¨Ï¥ÎCDO±H°e¶l¥ó¤£¥²³z¹LOutlook±H°e
§A°Ñ¦Ò³oºô­¶ http://blog.xuite.net/crdotlin/e ... 1%E9%83%B5%E4%BB%B6

¦pªG§A¦³GMAIL±b¸¹¡A¥u­n¤p­×§ï¤@¤U´N¨Ï¥Î
{...} ªí¥Ü»Ý­n¥Î CTRL+SHIFT+ENTER ¤TÁä¿é¤J¤½¦¡

TOP

¦^´_ 1# takeshilin88
Function ³Q§A¾ã­Ó§R±¼¤F¡A§A¥[¤F¤@­Ó¦P¦W¤lªºªÅªº´ß¡A·íµM¨S¥Î¡C
google §äªº¡A¤U­±ºô§}¦³­Ó RangetoHTML ¥i¯à¸ò§A­ì¥»ªº¤@¼Ë¥\¯à¡A§â¥¦¶K¦^¥h§a¡C
http://www.rondebruin.nl/win/s1/outlook/bmail2.htm
ªí¹F¤£²M¡BÃD·N¤£©ú½T¡B¨SªþÀɮ׮榡¡B¨S¦³°Q½×°ÝÃDªººA«×~~~~~~¥H¤W·R²ö¯à§U¡C

TOP

ÁÂÁ¦U¦ì¤j¤j¼ö¤ßªº¦^µª¡A·P¿E¤£ºÉ~~

¦]¬°¥²¶·­n¨Ï¥Î¤½¥q¦øªA¾¹¥D¾÷¨Ó±H°e¡A
¸Õ¹L¥ÎCDOª«¥ó±H¶l¥ó¥i¥H¦¨¥\¡C
¦ý¬O¶l¥ó±H¥X«á¡A¦³¥H¤U´X­Ó°ÝÃD«Ý¸Ñ¨M¡G
1.½Ð°Ý¥i¥H¦b.Send¶Ç°e¤§«e¥[¤W.Stop¡H¦nÅý§Ú¥i¥H·í¤U¬d¬Ý·Ç³Æ±H¥Xªº¶l¥ó¸ê®Æ¬O§_¦³»~
2.¶l¥ó±H¥X«á¡A±H¥ó³Æ¥÷¸Ì¨S¦³±H¥óªº¬ö¿ý¡A¸Ó¦p¦ó³B²z¡H
ÁÂÁÂ

TOP

        ÀR«ä¦Û¦b : ¤Hªº²´·úªø¦b«e­±¡A¥u¬Ý¨ì§O¤Hªº¯ÊÂI¡Aµ·²@¬Ý¤£¨ì¦Û¤vªº¯ÊÂI¡C
ªð¦^¦Cªí ¤W¤@¥DÃD