3

Я хотел бы отправить электронное сообщение многим пользователям с прикрепленными к нему личными данными, такими как пароли, которые нельзя отправить другим.

Пользователи и личные данные организованы по столбцам в файле Excel.

Я хотел бы автоматически отправлять электронное письмо каждому пользователю на основе этого файла, то есть сообщения для каждой строки и с использованием определенного шаблона сообщения.

В меню Excel я не смог найти такой вариант ...

Любая помощь?

Например:

Data.xls

Recipient   Password
a@a.com fjsdjg
b@a.com kjasdh
c@a.com laldwk
d@a.com kdfljf

Шаблон сообщения электронной почты:

Hello friends!

I created a survey on Google Docs named "XXX", with the
following link: http://XXX

To avoid double submitting or answers from people out of
our group, I created a password below for you. Please,
enter that on related field to validate your form.

######

Bye,
Me

2 ответа2

1

Лучший способ сделать это с помощью функции "Слияние писем" в Microsoft Word на вкладке почтовых рассылок. Это позволит вам отправить сообщение по адресам электронной почты, указанным в вашей электронной таблице, поскольку это дает вам возможность выбрать электронную таблицу для извлечения информации для слияния.

1

Вы также можете сделать это из VBA, используя Microsoft Outlook (или вы можете заменить функцию SendEmail в коде на любую другую реализацию отправки почты, которую вы захотите). Просто откройте вкладку «Разработчик» Visual Basic и поместите ее в модуль ThisWorkbook.

Option Explicit

Public Mail_Object As Object

Sub SU_458659()
    Dim numofrows As Integer
    Dim i As Integer
    Dim ws As Worksheet
    Dim startRow As Integer
    Dim emailColumn As Integer
    Dim passwordColumn As Integer

    'TWEAKABLE: Change this to the first row to process
    startRow = 2 'Assuming row 1 is header

    'TWEAKABLE: Change ActiveSheet to a sheet name, etc. if you don't want it to run on the currently "active" (selected) sheet
    Set ws = ActiveSheet

    'TWEAKABLE: Change this to the row number ("A" is 1) of the email address
    emailColumn = 1

    'TWEAKABLE: Change this to the row number ("B" is 2) of the password field
    passwordColumn = 2

    'Get the number of rows in the sheet
    numofrows = ws.Range("A1").Offset(ws.Rows.Count - 1, 0).End(xlUp).Row

    'Shouldn't have to tweak anything in here
    For i = startRow To numofrows
        Dim emailCell As Range
        Dim passwordCell As Range
        Set emailCell = ws.Cells(i, emailColumn)
        Set passwordCell = ws.Cells(i, passwordColumn)
        If Not IsEmpty(emailCell) Then
            Dim email As String
            Dim password As String
            email = CStr(emailCell.Value)
            password = CStr(passwordCell.Value)
            SendEmail email, password
        End If
    Next i
End Sub

Sub SendEmail(email As String, password As String)
    Dim emailSubject As String
    Dim emailSendFrom As String
    Dim emailCc As String
    Dim emailBcc As String
    Dim prePassword As String
    Dim postPassword As String
    Dim Mail_Single As Variant

    If Mail_Object Is Nothing Then Set Mail_Object = CreateObject("Outlook.Application")

    'TWEAKABLE: Email subject
    emailSubject = "CHANGE THIS"

    'TWEAKABLE: The 'from' email address
    emailSendFrom = "you@example.com"

    'TWEAKABLE: The CC: field (just make it the empty string "" if you don't want a CC
    emailCc = "nobody@example.com"

    'TWEAKABLE: The BCC: field (just make it the empty string "" if you don't want a BCC)
    emailBcc = "nobody@example.com"

    'TWEAKABLE: The email body BEFORE the password
    prePassword = "Your password is: """

    'TWEAKABLE: The email body AFTER the password - vbCrLf is a newline like hitting Enter
    postPassword = """." & vbCrLf & vbCrLf & "Have fun!"

    On Error GoTo debugs
    Set Mail_Single = Mail_Object.CreateItem(0)
    With Mail_Single
    .Subject = emailSubject
    .To = email
    .cc = emailCc
    .BCC = emailBcc
    .Body = prePassword & password & postPassword

    'TWEAKABLE: Remove the following three lines before ".send" to remove message box confirmation
    Dim retval As Variant
    retval = MsgBox("Do you want to send an email to " & email & " with the password " & password & "?", vbYesNo, "Confirmation")
    If retval = vbNo Then Exit Sub

    .send
    End With
debugs:
    If Err.Description <> "" Then MsgBox Err.Description
End Sub

Всё ещё ищете ответ? Посмотрите другие вопросы с метками .