2016-11-10 5 views
0

私はVBAの知識が非常に限られています。 私はリードコンタクトのスプレッドシートを持っています。私は選択した特定の人に電子メールを送信し、電子メールの本文に連絡先情報を返すドロップダウンリストを設定したいと思います。電子メールを自動入力する方法はわかりません。現時点では、ポップアップする電子メールは、セル内のテキスト値を返すのではなく、連絡先情報の本文に「true」を持っています。どのくらい正確にこれを修正するコードを追加するのですか?エクセルのスプレッドシートからリードアサインメントメールを作成

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

あなたはRange("K5")からOffsetている値を取得しようとしている場合、あなたはこのRange("K5").Offset(0, 3).Valueのように、.ValueOffsetを使用する必要があり、これはセルの右側にある値に3列を取得する「K5」 。

以下のコードは、あなたの電子メールの本文にセルにオフセット列を含む3つのセル「K5」から値を追加します。

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 
関連する問題