用vba 發yahoo GMAIL 的電子郵件不用透過outlook
- 帖子
- 67
- 主題
- 8
- 精華
- 0
- 積分
- 78
- 點名
- 0
- 作業系統
- Windows XP
- 軟體版本
- Excel 2010
- 閱讀權限
- 20
- 性別
- 男
- 註冊時間
- 2012-5-15
- 最後登錄
- 2021-9-14
|
- Option Explicit
- Sub SendAsPDF()
- ' Uses early binding
- ' Requires a reference to the Outlook Object Library
- Dim OutlookApp As Outlook.Application
- Dim MItem As Object
- Dim Recipient As String, Subj As String
- Dim Msg As String, Fname As String
-
- ' Message details
- Recipient = "[email protected]"
- Subj = "Sales figures"
- Msg = "Hey boss, here's the PDF file you wanted."
- Msg = Msg & vbNewLine & vbNewLine & "-Frank"
- Fname = Application.DefaultFilePath & "\" & _
- ActiveWorkbook.Name & ".pdf"
-
- ' Create the attachment
- ActiveSheet.ExportAsFixedFormat _
- Type:=xlTypePDF, _
- Filename:=Fname
-
- ' Create Outlook object
- Set OutlookApp = New Outlook.Application
-
- ' Create Mail Item and send it
- Set MItem = OutlookApp.CreateItem(olMailItem)
- With MItem
- .To = Recipient
- .Subject = Subj
- .Body = Msg
- .Attachments.Add Fname
- .Save 'to Drafts folder
- '.Send
- End With
- Set OutlookApp = Nothing
- ' Delete the file
- Kill Fname
- End Sub
複製代碼
|
|
|
|
|
|
|
|
- 帖子
- 67
- 主題
- 8
- 精華
- 0
- 積分
- 78
- 點名
- 0
- 作業系統
- Windows XP
- 軟體版本
- Excel 2010
- 閱讀權限
- 20
- 性別
- 男
- 註冊時間
- 2012-5-15
- 最後登錄
- 2021-9-14
|
註:上述程式碼,需要引用”Microsoft Outlook 12.0 Object Library"
|
|
|
|
|
|
|
|