销售/收购经理(AM)------------------------------- Alina(Alina@yahoo.com)< / p>
收购项目经理(APM)-------------------------- Benny(Benny@yahoo.com)
制造---------------------------------------------- ------朱(Julia@yahoo.com)
申请---------------------------------------------- -----------请选择(下拉列表,以便我可以选择)
AE外部传感器负责-------------------------------请选择(下拉列表,以便我可以选择)< / p>
我已经创建了一个单独的行(第59行Col A),其中我将上述行中的这些值组合在一起。
我必须制作一个宏来向这些多人发送1封电子邮件。我已经编写了一个发送电子邮件的代码,但我在某些时候陷入困境。我写了一个代码,取代了这个词 只要它在第59行中找到就选择“”,但不幸的是,该代码会永久地更改我不想要的行。 我想要的是,每当它找到一个单词时,请选择它只是忽略它,并且也不会改变单元格的格式。意味着我再次通过下拉列表更改一些新值,以便更改。如果你能帮助我,我将非常感谢你。非常感谢。请查看附带的照片。enter image description here enter image description here
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
答案 0 :(得分:1)
您不能在Replace()
the_string = Replace("the_string", "please select", " ")
附近加上引号
the_string = Replace(the_string, "please select", " ")
应该是:
Sub RemoveHypens()
With Sheets("Home").Range("A59")
.Value = Replace(.Value, "please select", " ")
End with
End Sub
这里对您的代码进行了轻微的重构,无需使用该变量:
Private Sub CommandButton1_Click()
Dim the_string As String
Dim i As Integer, Mail_Object, Email_Subject, o As Variant
Dim lr As Long
the_string = Sheets("Schedule_team").Range("A59").Value
the_string = Replace(the_string, "please select", " ")
Set Mail_Object = CreateObject("Outlook.Application")
With Mail_Object.CreateItem(o)
'.Subject = Range("B1").Value
.To = the_string
'.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
编辑:根据您更新的问题 -
{{1}}