2016-11-10 2 views
0

У меня очень ограниченное знание VBA. У меня есть таблица с ведущими контактами. Я хочу установить раскрывающийся список, который отправляет электронное письмо определенному человеку, которого я выбрал, и затем возвращает контактную информацию в теле письма. Я не знаю, как получить электронную почту для автоматического заполнения, и прямо сейчас, появившееся письмо имеет «истину» в теле для контактной информации, а не возвращает текстовое значение в ячейке. Как и именно ГДЕ добавить код, чтобы исправить это?Выполнение задания Назначение электронной почты из таблицы Excel

Sub DropDown7_Change() 

    Dim answer As String 

    answer = MsgBox("Are you sure you want to assign this lead?", _ 
     vbYesNo, "Send Email") 
    ' Above code informs the user that an automated email will be sent 

    'Code uses the users answer to either carryout the generated email process or to not save the changes. 
    If answer = vbNo Then Cancel = True 
    If Cancel = True Then Exit Sub 

    If answer = vbYes Then 
     'Connects to outlook and retrieves information needed to create and send the email. 
     Set OutlookApp = CreateObject("Outlook.Application") 
     Set OlObjects = OutlookApp.GetNamespace("MAPI") 
     Set newmsg = OutlookApp.CreateItem(olMailItem) 

     'Contains the email address of the person receiving the email. 
     newmsg.Subject = "Lead Assigned to You" 'Sets the automated subject line to the email 
     newmsg.Body = "Hello," & vbNewLine & _ 
      "You have been assigned a lead. Please follow up with the contact" & vbNewLine & _ 
      ActiveCell.Offset(0, 3).Range("K5").Select 
      ActiveCell.Offset(0, 6).Range("K5").Select 
      ActiveCell.Offset(0, 7).Range("K5").Select 

     'Above code has the body of the automated email 
     newmsg.Display 
    End If 

End Sub ' End of function 

ответ

0

Если вы пытаетесь получить значения, которые Offset к Range("K5"), то вам нужно использовать Offset с .Value, как этот Range("K5").Offset(0, 3).Value, это получит значение 3 колонки справа от клетки «К5» ,

Код ниже, добавят значения из 3-х ячеек с Колонным смещенных в ячейку «К5» к вам по электронной почте тело:

Sub DropDown7_Change() 

    Dim answer As String 

    answer = MsgBox("Are you sure you want to assign this lead?", _ 
     vbYesNo, "Send Email") 
    ' Above code informs the user that an automated email will be sent 

    'Code uses the users answer to either carryout the generated email process or to not save the changes. 
    If answer = vbNo Then 
     Exit Sub 
    Else 
     If answer = vbYes Then 

      'Connects to outlook and retrieves information needed to create and send the email. 
      Set OutlookApp = CreateObject("Outlook.Application") 
      Set OlObjects = OutlookApp.GetNamespace("MAPI") 
      Set newmsg = OutlookApp.CreateItem(olMailItem) 

      'Contains the email address of the person receiving the email. 
      newmsg.Subject = "Lead Assigned to You" 'Sets the automated subject line to the email 
      newmsg.body = "Hello," & vbNewLine & _ 
       "You have been assigned a lead. Please follow up with the contact" & vbNewLine & _ 
       Range("K5").Offset(0, 3).Value & vbNewLine & _ 
       Range("K5").Offset(0, 6).Value & vbNewLine & _ 
       Range("K5").Offset(0, 7).Value & vbNewLine      

      'Above code has the body of the automated email 
      newmsg.Display 
     End If 
    End If 

End Sub 
Смежные вопросы