Vba 发送电子邮件前,在excel中搜索给定的名称
我正在outlook中创建一个宏,以发送包含某些特定信息的eamil。但只有excel表格列表中的一些人才能发送该电子邮件。当他们在该宏上点击“发送”时,需要打开excel工作表并更改该人员是否在列表中。如果他不是,它应该给他一个错误“你没有资格发送此消息” 我可以使用下面的代码打开excel文件。但我不知道如何进行检查(姓名列在C1:C100的表1上),以查看发送人是否列在其中 下面是我的代码:Vba 发送电子邮件前,在excel中搜索给定的名称,vba,Vba,我正在outlook中创建一个宏,以发送包含某些特定信息的eamil。但只有excel表格列表中的一些人才能发送该电子邮件。当他们在该宏上点击“发送”时,需要打开excel工作表并更改该人员是否在列表中。如果他不是,它应该给他一个错误“你没有资格发送此消息” 我可以使用下面的代码打开excel文件。但我不知道如何进行检查(姓名列在C1:C100的表1上),以查看发送人是否列在其中 下面是我的代码: [Dim strFldr As String Dim OutMail As Object Dim
[Dim strFldr As String
Dim OutMail As Object
Dim xlApp As Object
strFldr = "C:\\users-d\gxg063\Gift\test\"
Set xlApp = CreateObject("Excel.Application")
xlApp.Application.Visible = True
xlApp.Workbooks.Open strFldr & "\RegionalAuthority.xlsx"]
您如何检查当前用户的名称?您正在使用Windows名称吗?这只是针对sheet1中的每个单元格引用它们的名称。范围(“C1:C100”)是的,我使用的是windows名称。你能给我一些代码从宏中引用它吗?很好,它正按照我的预期工作。我唯一想做的额外工作是在参考中启用“Microsoft Excel 14.0对象库”。非常感谢Jiminy Cricket。对不起,我只是不知道如何回答这个问题。你能让我知道吗?点击我答案旁边的勾号。谢谢
Let me know how this works out - you'll need a reference to Excel in your Outloook VBE
Sub TestSub()
Dim strFldr As String
Dim OutMail As Object
Dim xlApp As Excel.Application
Dim xlWb As Workbook
Dim xlWs As Worksheet
Dim r As Range
Dim User As String
Dim c As Range
strFldr = "C:\\users-d\gxg063\Gift\test\"
Set xlApp = New Excel.Application
Set xlWb = xlApp.Workbooks.Open(strFldr & "\RegionalAuthority.xlsx")
Set xlWs = xlWb.Worksheets("Sheet1")
Set r = xlWs.Range("C1:C100")
User = (Environ$("Username"))
For Each c In r
If c = User Then
'Call your Send Macro here
Exit For
End If
Next c
xlApp.Visible = True
Set xlApp = Nothing
Set xlWb = Nothing
Set xlWs = Nothing
End Sub