Board logo

標題: 用vba 發yahoo GMAIL 的電子郵件不用透過outlook [打印本頁]

作者: alims    時間: 2012-6-2 12:37     標題: 用vba 發yahoo GMAIL 的電子郵件不用透過outlook

用vba 發yahoo GMAIL 的電子郵件不用透過outlook

Sub outfile()
Set myOL = CreateObject("outlook.application")
Set myMail = myOL.createItem(0)
myMail.to = "[email protected]"
myMail.Subject = "see you sooon"
myMail.body = "execl send to Mail...."
myMail.Display
myMail.send
End Sub
有類似以上的格式  最能夾帶附件
能自動化發email
作者: alumi    時間: 2012-6-2 18:24


  1. Option Explicit

  2. Sub SendAsPDF()
  3. '   Uses early binding
  4. '   Requires a reference to the Outlook Object Library
  5.     Dim OutlookApp As Outlook.Application
  6.     Dim MItem As Object
  7.     Dim Recipient As String, Subj As String
  8.     Dim Msg As String, Fname As String
  9.             
  10. '   Message details
  11.     Recipient = "[email protected]"
  12.     Subj = "Sales figures"
  13.     Msg = "Hey boss, here's the PDF file you wanted."
  14.     Msg = Msg & vbNewLine & vbNewLine & "-Frank"
  15.     Fname = Application.DefaultFilePath & "\" & _
  16.       ActiveWorkbook.Name & ".pdf"
  17.    
  18. '   Create the attachment
  19.     ActiveSheet.ExportAsFixedFormat _
  20.         Type:=xlTypePDF, _
  21.         Filename:=Fname
  22.    
  23. '   Create Outlook object
  24.     Set OutlookApp = New Outlook.Application
  25.    
  26. '   Create Mail Item and send it
  27.     Set MItem = OutlookApp.CreateItem(olMailItem)
  28.     With MItem
  29.       .To = Recipient
  30.       .Subject = Subj
  31.       .Body = Msg
  32.       .Attachments.Add Fname
  33.       .Save 'to Drafts folder
  34.       '.Send
  35.     End With
  36.     Set OutlookApp = Nothing

  37. '   Delete the file
  38.     Kill Fname
  39. End Sub
複製代碼


作者: alumi    時間: 2012-6-2 18:28


註:上述程式碼,需要引用”Microsoft Outlook 12.0 Object Library"


作者: Hsieh    時間: 2012-6-2 23:46

回復 1# alims

使用gmail的帳號來發郵件- 傳送多個附件
作者: alims    時間: 2012-6-5 12:32

十分感謝  大大 無私的救援




歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)