標題:
為何執行excel vba之後信件仍停在outlook寄件夾呢?
[打印本頁]
作者:
dechiuan999
時間:
2010-9-12 17:47
標題:
為何執行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 = "
[email protected]
"
.Subject = "These one files"
.Body = "測試信件"
.Attachments.Add CurrFile
'.Display
.Send
End With
Set olMail = Nothing
Set olApp = Nothing
End Sub
感謝各位大大。
作者:
jackdream
時間:
2010-9-13 13:42
回復
1#
dechiuan999
可能是卡在OutLook 安全性,試試 CDO寄信方式
相關網頁:
http://www.pro-soho.com/Blog/article.asp?id=295
http://aqr199xx.pixnet.net/blog/post/23750101
作者:
dechiuan999
時間:
2010-9-13 15:27
感謝大大。
小弟先收下
試試。
感恩!
作者:
dechiuan999
時間:
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 = "
[email protected]
"
myMail.To = "
[email protected]
"
myMail.CC = "
[email protected]
"
myMail.TextBody = "AUTO PARTS"
myMail.AddAttachment (mFile)
myMail.Send
Set myMail = Nothing
TextBox1.Text = ""
TextBox1.SetFocus
End Sub
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)