2013-02-20 32 views
7

में एकाधिक प्राप्तकर्ताओं को ईमेल भेजने के लिए मैं Outlook का उपयोग कैसे कर सकता हूं मैं लोगों के विभिन्न समूहों को ईमेल करने के लिए Excel फ़ॉर्म पर कई बटन सेट अप करने का प्रयास कर रहा हूं। मैंने अलग-अलग ईमेल पते सूचीबद्ध करने के लिए अलग वर्कशीट पर सेल्स की कई श्रेणियां बनाई हैं। उदाहरण के लिए, मैं Outlook को खोलने के लिए "बटन ए" चाहता हूं और "वर्कशीट बी: सेल डी 3-डी 6" से ईमेल पतों की सूची डालता हूं। फिर जो कुछ करना है उसे Outlook में "भेजें" मारा जाता है।एक्सेल वीबीए

यहां मेरा वीबीए कोड है, लेकिन मैं इसे काम नहीं कर सकता। क्या कोई मुझे बता सकता है कि मैं क्या खो रहा हूं या गलत कर रहा हूं, कृपया?

वीबी:

Sub Mail_workbook_Outlook_1() 
    'Working in 2000-2010 
    'This example send the last saved version of the Activeworkbook 
    Dim OutApp As Object 
    Dim OutMail As Object 

    EmailTo = Worksheets("Selections").Range("D3:D6") 

    Set OutApp = CreateObject("Outlook.Application") 
    Set OutMail = OutApp.CreateItem(0) 

    On Error Resume Next 
    With OutMail 
     .To = EmailTo 
     .CC = "[email protected];[email protected]" 
     .BCC = "" 
     .Subject = "RMA #" & Worksheets("RMA").Range("E1") 
     .Body = "Attached to this email is RMA #" & Worksheets("RMA").Range("E1") & ". Please follow the instructions for your department included in this form." 
     .Attachments.Add ActiveWorkbook.FullName 
     'You can add other files also like this 
     '.Attachments.Add ("C:\test.txt") 

     .Display 
    End With 
    On Error Goto 0 

    Set OutMail = Nothing 
    Set OutApp = Nothing 
End Sub 
+0

आप भी [Recipient.Add] का उपयोग कर सकते (http://stackoverflow.com/questions/13019651/automated-email-generation-not-resolving-multiple- प्राप्तकर्ता) – SeanC

उत्तर

13

आप रेंज "D3:D6" की हर कोशिका के माध्यम से लूप करने के लिए है और अपने To स्ट्रिंग का निर्माण। बस इसे एक संस्करण में असाइन करना उद्देश्य को हल नहीं करेगा। EmailTo एक सरणी बन जाता है यदि आप सीधे सीमा को असाइन करते हैं। आप इसे भी कर सकते हैं लेकिन फिर आपको अपने To स्ट्रिंग

बनाने के लिए सरणी के माध्यम से लूप करना होगा, क्या आप यह कोशिश कर रहे हैं? (की कोशिश की और परीक्षण किया)

Option Explicit 

Sub Mail_workbook_Outlook_1() 
    'Working in 2000-2010 
    'This example send the last saved version of the Activeworkbook 
    Dim OutApp As Object 
    Dim OutMail As Object 
    Dim emailRng As Range, cl As Range 
    Dim sTo As String 

    Set emailRng = Worksheets("Selections").Range("D3:D6") 

    For Each cl In emailRng 
     sTo = sTo & ";" & cl.Value 
    Next 

    sTo = Mid(sTo, 2) 

    Set OutApp = CreateObject("Outlook.Application") 
    Set OutMail = OutApp.CreateItem(0) 

    On Error Resume Next 
    With OutMail 
     .To = sTo 
     .CC = "[email protected];[email protected]" 
     .BCC = "" 
     .Subject = "RMA #" & Worksheets("RMA").Range("E1") 
     .Body = "Attached to this email is RMA #" & _ 
     Worksheets("RMA").Range("E1") & _ 
     ". Please follow the instructions for your department included in this form." 
     .Attachments.Add ActiveWorkbook.FullName 
     'You can add other files also like this 
     '.Attachments.Add ("C:\test.txt") 

     .Display 
    End With 
    On Error GoTo 0 

    Set OutMail = Nothing 
    Set OutApp = Nothing 
End Sub 
+0

टूल्स -> संदर्भ -> माइक्रोसॉफ्ट आउटलुक ऑब्जेक्ट लाइब्रेरी – easycheese

+0

पर जाने के लिए मत भूलना, आपको इसकी आवश्यकता नहीं है;) मैं देर बाध्यकारी का उपयोग कर रहा हूं :) –

+0

कोई विचार नहीं कि यह क्या है :) मैं बस भाग गया उस समस्या में। – easycheese

1
ToAddress = "[email protected]" 
ToAddress1 = "[email protected]" 
ToAddress2 = "[email protected]" 
MessageSubject = "It works!." 
Set ol = CreateObject("Outlook.Application") 
Set newMail = ol.CreateItem(olMailItem) 
newMail.Subject = MessageSubject 
newMail.RecipIents.Add(ToAddress) 
newMail.RecipIents.Add(ToAddress1) 
newMail.RecipIents.Add(ToAddress2) 
newMail.Send