為何執行excel vba之後信件仍停在outlook寄件夾呢?
- 帖子
- 231
- 主題
- 55
- 精華
- 0
- 積分
- 293
- 點名
- 0
- 作業系統
- winxp
- 軟體版本
- office2003
- 閱讀權限
- 20
- 性別
- 男
- 來自
- KEELUNG
- 註冊時間
- 2010-7-24
- 最後登錄
- 2018-8-28
|
為何執行excel vba之後信件仍停在outlook寄件夾呢?
各位大大好:
小弟利用EXCEL VBA方式E-MAIL
文件資料並隨附檔案。可是卻發現執行之後;
該E-MAIL信件資料仍停留在OUTLOOK寄件夾內。
非要去開啟OUTLOOK再按執行寄件的動作才會
將此信件寄送出去呢?
'outlook 2002版本
'excel 2002版本
Sub SendWithAtt()
'引用Microsoft outlook object library
Dim olApp As Outlook.Application
Dim olMail As MailItem
Dim CurrFile As String
Set olApp = New Outlook.Application
Set olMail = olApp.CreateItem(olMailItem)
CurrFile = "d:\temp\test.txt"
With olMail
.To = "test123@yahoo.com.tw"
.Subject = "These one files"
.Body = "測試信件"
.Attachments.Add CurrFile
'.Display
.Send
End With
Set olMail = Nothing
Set olApp = Nothing
End Sub
感謝各位大大。 |
|
|
|
|
|
|
- 帖子
- 231
- 主題
- 55
- 精華
- 0
- 積分
- 293
- 點名
- 0
- 作業系統
- winxp
- 軟體版本
- office2003
- 閱讀權限
- 20
- 性別
- 男
- 來自
- KEELUNG
- 註冊時間
- 2010-7-24
- 最後登錄
- 2018-8-28
|
4#
發表於 2010-9-17 10:00
| 只看該作者
謝謝大大。
小弟引用下語法
已可達成e-mail了。
'Microsoft CDO for Windows 2000 Library
Private Sub CommandButton1_Click()
Dim mPath As String
Dim mFilename As String, mFile$
Dim mStr$
Dim myMail As Object
mPath = "D:\temp\"
mFilename = TextBox1.Text
If Len(mFilename) = 0 Then
MsgBox "請先輸入客戶編號"
Exit Sub
End If
mFile = mPath & mFilename & ".pdf"
mStr = Dir(mFile)
If Len(mStr) = 0 Then
MsgBox "輸入檔名不存在" & vbCrLf & vbCrLf & "請重新輸入檔名"
Exit Sub
End If
Set myMail = CreateObject("CDO.Message")
myMail.BodyPart.Charset = "big5"
myMail.Subject = "KUOZUI MOTORS LTD" & mFilename
myMail.Subject = "CUSTOMER CORP" & mFilename
myMail.From = "aaaa@msa.hinet.net"
myMail.To = "bbbbbb@gmail.com"
myMail.CC = "cccc@yahoo.com.tw"
myMail.TextBody = "AUTO PARTS"
myMail.AddAttachment (mFile)
myMail.Send
Set myMail = Nothing
TextBox1.Text = ""
TextBox1.SetFocus
End Sub |
|
|
|
|
|
|
- 帖子
- 231
- 主題
- 55
- 精華
- 0
- 積分
- 293
- 點名
- 0
- 作業系統
- winxp
- 軟體版本
- office2003
- 閱讀權限
- 20
- 性別
- 男
- 來自
- KEELUNG
- 註冊時間
- 2010-7-24
- 最後登錄
- 2018-8-28
|
3#
發表於 2010-9-13 15:27
| 只看該作者
|
|
|
|
|
|
- 帖子
- 133
- 主題
- 9
- 精華
- 0
- 積分
- 147
- 點名
- 0
- 作業系統
- Win10
- 軟體版本
- Office 2010
- 閱讀權限
- 20
- 性別
- 男
- 來自
- 高雄
- 註冊時間
- 2010-5-1
- 最後登錄
- 2024-11-11
|
2#
發表於 2010-9-13 13:42
| 只看該作者
|
|
|
|
|
|