返回列表 上一主題 發帖

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


  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
複製代碼

TOP


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

TOP

        靜思自在 : 君子立恆志,小人恆立志。
返回列表 上一主題