Discussion:
請問 用EXCEL當Email資料 的來源 來寄outlook 的信
(时间太久无法回复)
yihren
2008-10-22 15:40:01 UTC
Permalink
如題所述
用了一段VBA

Sub 寄EMAIL()

Dim i As Integer
Dim myOlApp As Outlook.Application
Dim myMail As Outlook.MailItem
Dim myBody As String
Dim Receiver As String
Set myOlApp = CreateObject("OutLook.Application")
For i = 1 To 100
Set myMail = myOlApp.CreateItem(olMailItem)
myMail.Fristname = Cells(2 + i, 4).Value
myMail.item01 = Cells(2 + i, 5).Value
Receiver = Cells(2 + i, 6).Value
myBody = myMail.Fristname & "先生" & vbCrLf & vbCrLf
myBody = myBody & "標題為:" & vbCrLf
myBody = myBody & myMail.item01
With myMail
.To = Receiver '收件人地址
.Subject = "如信件內容" '郵件主體
.Body = myBody '信件內容
'.Attachments.Add AttachedObject '黏貼附件
.Display
.Send
End With
Next i
Set myOlApp = Nothing

End Sub

為什麼 myMail.Fristname = Cells(2 + i, 4).Value
myMail.item01 = Cells(2 + i, 5).Value
這兩行不能執行 請各位大大救救我
天道無常
2008-10-23 03:05:27 UTC
Permalink
因為 myMail 裡沒有那項 property.

在你的程式裡,打入 "myMail.",會出現一個視窗.裡面找不到firstname. (你的
first 拼錯).我只找到 sendername.
Post by yihren
如題所述
用了一段VBA
Sub 寄EMAIL()
Dim i As Integer
Dim myOlApp As Outlook.Application
Dim myMail As Outlook.MailItem
Dim myBody As String
Dim Receiver As String
Set myOlApp = CreateObject("OutLook.Application")
For i = 1 To 100
Set myMail = myOlApp.CreateItem(olMailItem)
myMail.Fristname = Cells(2 + i, 4).Value
myMail.item01 = Cells(2 + i, 5).Value
Receiver = Cells(2 + i, 6).Value
myBody = myMail.Fristname & "先生" & vbCrLf & vbCrLf
myBody = myBody & "標題為:" & vbCrLf
myBody = myBody & myMail.item01
With myMail
.To = Receiver '收件人地址
.Subject = "如信件內容" '郵件主體
.Body = myBody '信件內容
'.Attachments.Add AttachedObject '黏貼附件
.Display
.Send
End With
Next i
Set myOlApp = Nothing
End Sub
為什麼 myMail.Fristname = Cells(2 + i, 4).Value
myMail.item01 = Cells(2 + i, 5).Value
這兩行不能執行 請各位大大救救我
yihren
2008-10-23 05:14:01 UTC
Permalink
大大 你好
感謝你的回覆
mymail 不是可以自訂義的property 嗎?
那我應該用甚麼方式來讀取EXCEL 第4欄的姓 以及第五欄的標題呢?
謝謝

"天道無常" 來函:
Post by 天道無常
因為 myMail 裡沒有那項 property.
在你的程式裡,打入 "myMail.",會出現一個視窗.裡面找不到firstname. (你的
first 拼錯).我只找到 sendername.
Post by yihren
如題所述
用了一段VBA
Sub 寄EMAIL()
Dim i As Integer
Dim myOlApp As Outlook.Application
Dim myMail As Outlook.MailItem
Dim myBody As String
Dim Receiver As String
Set myOlApp = CreateObject("OutLook.Application")
For i = 1 To 100
Set myMail = myOlApp.CreateItem(olMailItem)
myMail.Fristname = Cells(2 + i, 4).Value
myMail.item01 = Cells(2 + i, 5).Value
Receiver = Cells(2 + i, 6).Value
myBody = myMail.Fristname & "先生" & vbCrLf & vbCrLf
myBody = myBody & "標題為:" & vbCrLf
myBody = myBody & myMail.item01
With myMail
.To = Receiver '收件人地址
.Subject = "如信件內容" '郵件主體
.Body = myBody '信件內容
'.Attachments.Add AttachedObject '黏貼附件
.Display
.Send
End With
Next i
Set myOlApp = Nothing
End Sub
為什麼 myMail.Fristname = Cells(2 + i, 4).Value
myMail.item01 = Cells(2 + i, 5).Value
這兩行不能執行 請各位大大救救我
天道無常
2008-10-23 23:21:03 UTC
Permalink
程式很笨,你要定義新的property,要先告知程式,不是自行設定一個,程式就會
自動知道那是什麼.你那個object若無所要的性質或功能,得先衍生一個新的
object,加上所要的性質功能,才能使用.

試試 myMail.sendername = Cells(2 + i, 4).Value 看看.其他的按我說的方
法,到myMail裡去找找看有沒有什麼可用的性質.我未曾自Excel中傳送郵件,故
不知曉詳細步驟.可以上網查 send outlook email from excel,應該可以查到不
少資料.
Post by yihren
大大 你好
感謝你的回覆
mymail 不是可以自訂義的property 嗎?
那我應該用甚麼方式來讀取EXCEL 第4欄的姓 以及第五欄的標題呢?
謝謝
"天道無常" 來函:
Post by 天道無常
因為 myMail 裡沒有那項 property.
在你的程式裡,打入 "myMail.",會出現一個視窗.裡面找不到firstname. (你的
first 拼錯).我只找到 sendername.
Post by yihren
如題所述
用了一段VBA
Sub 寄EMAIL()
Dim i As Integer
Dim myOlApp As Outlook.Application
Dim myMail As Outlook.MailItem
Dim myBody As String
Dim Receiver As String
Set myOlApp = CreateObject("OutLook.Application")
For i = 1 To 100
Set myMail = myOlApp.CreateItem(olMailItem)
myMail.Fristname = Cells(2 + i, 4).Value
myMail.item01 = Cells(2 + i, 5).Value
Receiver = Cells(2 + i, 6).Value
myBody = myMail.Fristname & "先生" & vbCrLf & vbCrLf
myBody = myBody & "標題為:" & vbCrLf
myBody = myBody & myMail.item01
With myMail
.To = Receiver '收件人地址
.Subject = "如信件內容" '郵件主體
.Body = myBody '信件內容
'.Attachments.Add AttachedObject '黏貼附件
.Display
.Send
End With
Next i
Set myOlApp = Nothing
End Sub
為什麼 myMail.Fristname = Cells(2 + i, 4).Value
myMail.item01 = Cells(2 + i, 5).Value
這兩行不能執行 請各位大大救救我
yihren
2008-10-25 04:41:01 UTC
Permalink
謝謝 大大 我把mymail 刪掉 果然就可以用了

"天道無常" 來函:
Post by 天道無常
程式很笨,你要定義新的property,要先告知程式,不是自行設定一個,程式就會
自動知道那是什麼.你那個object若無所要的性質或功能,得先衍生一個新的
object,加上所要的性質功能,才能使用.
試試 myMail.sendername = Cells(2 + i, 4).Value 看看.其他的按我說的方
法,到myMail裡去找找看有沒有什麼可用的性質.我未曾自Excel中傳送郵件,故
不知曉詳細步驟.可以上網查 send outlook email from excel,應該可以查到不
少資料.
Post by yihren
大大 你好
感謝你的回覆
mymail 不是可以自訂義的property 嗎?
那我應該用甚麼方式來讀取EXCEL 第4欄的姓 以及第五欄的標題呢?
謝謝
"天道無常" 來函:
Post by 天道無常
因為 myMail 裡沒有那項 property.
在你的程式裡,打入 "myMail.",會出現一個視窗.裡面找不到firstname. (你的
first 拼錯).我只找到 sendername.
Post by yihren
如題所述
用了一段VBA
Sub 寄EMAIL()
Dim i As Integer
Dim myOlApp As Outlook.Application
Dim myMail As Outlook.MailItem
Dim myBody As String
Dim Receiver As String
Set myOlApp = CreateObject("OutLook.Application")
For i = 1 To 100
Set myMail = myOlApp.CreateItem(olMailItem)
myMail.Fristname = Cells(2 + i, 4).Value
myMail.item01 = Cells(2 + i, 5).Value
Receiver = Cells(2 + i, 6).Value
myBody = myMail.Fristname & "先生" & vbCrLf & vbCrLf
myBody = myBody & "標題為:" & vbCrLf
myBody = myBody & myMail.item01
With myMail
.To = Receiver '收件人地址
.Subject = "如信件內容" '郵件主體
.Body = myBody '信件內容
'.Attachments.Add AttachedObject '黏貼附件
.Display
.Send
End With
Next i
Set myOlApp = Nothing
End Sub
為什麼 myMail.Fristname = Cells(2 + i, 4).Value
myMail.item01 = Cells(2 + i, 5).Value
這兩行不能執行 請各位大大救救我
Loading...