简体   繁体   English

如何忽略单元格中一组单词中的特定单词,并向一群人发送一封电子邮件?

[英]How to ignore specific word from a group of words in a cell and send one email to group of people?

I am new to VBA. 我是VBA的新手。 I am working hard and learning it but there is a point where I am stuck now. 我正在努力学习,但是现在有一个问题。 If someone please help me out then I shall be grateful. 如果有人请帮助我,我将不胜感激。 I have a drop down list in excel like 我在excel中有一个下拉列表,例如

 Sales/Acquisition Manager (AM)         Alina (Alina@yahoo.com)
 Acquisition Project Manager (APM)      Benny(Benny@yahoo.com)
 Manufacturing                          Julia(Julia@yahoo.com)
 Application                            please select (drop down list so I can choose)
 AE external sensor responsible         please select (Drop down list so I can choose)

I have made a separate row (row 59 Col A) where I have combined these values from the above rows. 我做了一个单独的行(第59行A列),在这里我合并了以上各行的这些值。

I have to make a macro to send 1 email to these multiple people. 我必须做一个宏才能向这些多人发送1封电子邮件。 I have written a code for sending email but I am stuck at another point. 我已经编写了用于发送电子邮件的代码,但是我被困在其他地方。 I have written code which replaces the words please select with “ ” whenever it finds it in row 59 but unfortunately that code changes the line permanently which I don't want. 我写的代码取代了的话please select以“”只要找到它排59,但不幸的代码永久改变了线,我不想。

What I want is that whenever it finds the words please select in a row it just ignores it and and also doesn't change the format of cell. 我想要的是,只要找到单词, please select连续please select它,它只会忽略它,并且不会更改单元格的格式。 Means when I again change some new value by drop down list so it got changed. 表示当我再次通过下拉列表更改一些新值时,它被更改了。

Private Sub CommandButton1_Click()
  Dim the_string As String
  the_string = Sheets("Schedule_team").Range("A59")
  the_string = Replace(the_string, "please select", " ")

  Sheets("Schedule_team").Range("A59") = the_string

  MsgBox (Sheets("Schedule_team").Range("A59"))

  Dim i As Integer, Mail_Object, Email_Subject, o As Variant, lr As Long, x As Variant

  Set Mail_Object = CreateObject("Outlook.Application")

  x = Cells (59, 1).Value
  With Mail_Object.CreateItem(o)
    ' .Subject = Range("B1").Value
      .To = x
    ' .Body = Range("B2").Value
    ' .Send
      .display 'disable display and enable send to send automatically
  End With

  MsgBox "E-mail successfully sent", 64
  Application.DisplayAlerts = False
  Set Mail_Object = Nothing
End Sub

Pull the contents of A59 into the string, replace as needed, then just use that string instead of copying it back to the sheet. 将A59的内容拉入字符串中,根据需要进行替换,然后仅使用该字符串,而不是将其复制回到工作表中。

Untested, just used your code 未经测试,仅使用您的代码

Private Sub CommandButton1_Click()
  Dim Mail_Object as Object
  Dim the_string As String

  the_string = Sheets("Schedule_team").Range("A59")
  the_string = Replace(the_string, "please select", " ")

  Set Mail_Object = CreateObject("Outlook.Application")

  With Mail_Object.CreateItem(o)
    ' .Subject = Range("B1")
    .To = the_string
    ' .Body = Range("B2")
    ' .Send
    .Display 'disable display and enable send to send automatically
  End With

  MsgBox "E-mail successfully sent", 64
End Sub

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果相应单元格包含“过期”一词,如何将 email 发送给特定收件人? - How to send email to specific recipients if corresponding cell contains the word " expired"? Excel在同一列中向所有人发送电子邮件,只需要向特定单元格中的所有人发送电子邮件。 怎么样? - Excel sending emails to all people in one Column, need to email only person in specific cell. How? Excel VBA:如何向Outlook中的组发送电子邮件? - Excel VBA: How to send email to group in outlook? 如何将文本从 Excel 发送到 Word,其中一个单词(单元格)为粗体? - How to send text from Excel to Word where one word (cell) is bold? 当用户使用 powerapps 和 excel 单击发送按钮时,如何向特定人群发送文本警报消息 - How to send a text alert message to particular group of people when user clikc on send button using powerapps and excel 如何根据所选单元格@VBA 从一组单元格中插入特定数据 - How to insert specific data from a group of cells depending on the selected cell @VBA 如何向列中的所有人发送一封电子邮件 - How to send a single email to all people in a column 如果单元格包含“过期”一词,则发送 email - Send an email if the cell contains the word “expired” 计算一个单词列表中有多少个单词出现在一个单元格中 - count how many words from a word list appear in a cell 如何通过从Outlook联系人列表中获取电子邮件地址来向A列中的人的姓名发送电子邮件? - How to send an email to names of people in column A by getting their email address from outlook contact list?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM