2017-04-25 154 views
-2

我試圖從Excel工作表發送郵件發送郵件,我的VBA不工作Excel VBA中從Excel工作表

錯誤我得到的「對象不suppoer此屬性或方法」爲所有getelement聲明。

我有excel表中的數據,如recieptent,主題,消息。

代碼,我現在用的就是,

Sub Macro2() 
Do Until IsEmpty(ActiveCell) 
URL = Selection.Value 'https://mail.google.com/mail/u/0/?ui=2&view=cm&fs=1&tf=1 
Set ie = CreateObject("InternetExplorer.Application") 
With ie 
    .Visible = 1 
    .navigate URL 
    While .Busy Or .readyState <> 4 
    DoEvents 
    Wend 
End With 
Dim Doc As HTMLDocument 
Set Doc = ie.document 
ie.document.getElementByName(":oa").Value = ActiveCell.Offset(0, 1).Value 'reciever_mail_id 
ie.document.getElementById(":op").Value = ActiveCell.Offset(0, 2).Value 'subject 
ie.document.getElementById(":nq").Value = ActiveCell.Offset(0, 3).Value 'message 
ie.document.getElementById(":p0").Click 'submit button 
ActiveCell.Offset(0, 4).Value = "mail sent" 
ActiveCell.Offset(1, 0).Select 
ie.Quit 
Loop 
End Sub 

*我的Gmail ID已登錄,因此無需登錄。 **我是初學者在VBA,需要從專家的幫助。

+0

您是否獲得在上面的代碼中的錯誤?或者你需要其他幫助? –

+0

我得到的錯誤是「對象不支持此屬性或方法」的所有getelement語句。 –

+0

你可以使用MS Outlook嗎?通過一個網站的界面發送它似乎有點笨重,Outlook確實提供了很好的發送電子郵件的功能 –

回答

0

GetElementByName不存在。

你想使用GetElementsByName這將返回一個HTMLCollection,而不是一個簡單的HTMLElement。

所以如果有這個名字只有一個元素寫:ie.document.getElementsByName(":oa")(0).Value