如何从行中选定的单元格和相邻单元格中检索信息?

时间:2021-03-18 02:27:34

I want to populate an Outlook email with information from a row of cells after selecting one cell in the row. The information for each row is the following:

我想在行中选择一个单元格后,用一行单元格中的信息填充Outlook电子邮件。每行的信息如下:

  • Column A: Email
  • A栏:电子邮件
  • Column B: Name
  • B栏:名称
  • Column C: Message
  • C栏:消息

How do I reference the cells in column B and column C after first selecting an email address in column A.

首先在A列中选择电子邮件地址后,如何引用B列和C列中的单元格。

Sub populateEmail()
Dim outApp, myItem, myAddress, bodyString, location
Set myAddress = Selection
Set outApp = CreateObject("Outlook.Application")
Set myItem = outApp.CreateItem(0)


 'populate bodyString with information on selected row


With myItem
    .Subject = "subject"
    .To = myAddress
    .Body = bodyString
    .Display
End With

End Sub

1 个解决方案

#1


0  

If the selected cell is in column A (which I assume your macro is relying on based on your Set myAddress = Selection) then other columns can be easily referenced using the Offset property.

如果所选单元格位于A列(我假设您的宏依赖于您的Set myAddress = Selection),则可以使用Offset属性轻松引用其他列。

So column B could be referenced using Selection.Offset(0, 1), and column C could be referenced using Selection.Offset(0, 2).

因此可以使用Selection.Offset(0,1)引用列B,并且可以使用Selection.Offset(0,2)引用列C.

You could therefore create a string for the body of your email using something like:

因此,您可以使用以下内容为您的电子邮件正文创建一个字符串:

bodyString = "Dear " & Selection.Offset(0, 1).Value & "," & vbCrLf & _
             Selection.Offset(0, 2).Value

#1


0  

If the selected cell is in column A (which I assume your macro is relying on based on your Set myAddress = Selection) then other columns can be easily referenced using the Offset property.

如果所选单元格位于A列(我假设您的宏依赖于您的Set myAddress = Selection),则可以使用Offset属性轻松引用其他列。

So column B could be referenced using Selection.Offset(0, 1), and column C could be referenced using Selection.Offset(0, 2).

因此可以使用Selection.Offset(0,1)引用列B,并且可以使用Selection.Offset(0,2)引用列C.

You could therefore create a string for the body of your email using something like:

因此,您可以使用以下内容为您的电子邮件正文创建一个字符串:

bodyString = "Dear " & Selection.Offset(0, 1).Value & "," & vbCrLf & _
             Selection.Offset(0, 2).Value