2016-12-01 83 views
-1

所有我想弄清楚我尝试过的问题,但没有成功。任何人都可以请帮我解决这个问题。我会感激你的。 任务: 我有一个excel下拉列表,如如何从单元格中的单词组中筛选出特定的单词

销售/采购经理(AM)-------------------------- ----- Alina([email protected]

收购项目经理(APM)-------------------------- Benny ([email protected]

制造-------------------------------------- -------------- Julia([email protected]

应用程序----------------------- ----------------------------------请选择(下拉列表,以便我可以选择)

AE外部传感器负责-------------------------------请选择(下拉列表以便我可以选择)

我已经做了一个单独的行(行59列A),其中我结合了上述行中的这些值。

我必须让一个宏发送1封电子邮件给这些多人。我写了一个发送电子邮件的代码,但我在某个时候被卡住了。我已经写了一个代码,它代替了
这个词,只要它在第59行中找到就用“”选择,但不幸的是,代码会永久更改我不想要的行。 我想要的是,只要它发现一个字,请选择一行,它只是忽略它,并且也不要更改单元格的格式。意思是当我再次通过下拉列表更改一些新值时,它就发生了变化。如果你能帮我解决这个问题,我将非常感激你。非常感谢。请检查附件中的照片。 enter image description hereenter 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 

回答

1

你不把引号the_stringReplace()

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 
+0

非常感谢您的合作。它的工作,但我有一个问题,我想忽略这个词,请选择它的文本时,但是当我使用命令替换,然后它改变单元格的值永久。 我在做什么是我有一个下拉列表,通过它我改变了电子邮件地址,所以我需要的是写一个代码,只要请选择进来单元格(59,1)它忽略它,但不会改变函数细胞永久。 – Peter

+0

目前尚不清楚你在做什么。这将有助于扩大你的问题,列出你想要执行的确切步骤,包括解释你的“下拉式方法” - 我不知道你可能会这么做。 –

+0

请查看最新的代码,问题和数字。现在我试图解释我想做什么以及我在做什么。我希望它现在能工作。非常感谢。 – Peter

相关问题