在隐藏 sheet 中找到两个单元格值并存储为字符串

Find two cells values in hidden sheet and store as string

我的想法是制作一个(忘记密码)表单,它将恢复(用户名)和(密码)并通过用户提供的电子邮件地址发送。在下图中,客户将输入他的电子邮件地址,因此程序代码将在隐藏的 sheet table 中找到完全匹配的电子邮件地址,如果匹配,接下来的两个单元格将存储为一个字符串。

正如您在下面看到的那样,这是隐藏的 sheet 和 table,其中包含有关注册客户的信息,因此当我们收到与(用户名)和(密码)匹配的电子邮件时,存储为字符串 ((!!without activating or see this sheet!!))

这是我当前的代码:

Public Function send_email()
Dim NUser As String
Dim NPass As String
Dim info As Variant
Set cdomsg = CreateObject("CDO.message")
With cdomsg.Configuration.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smptserverport") = "587"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "dash32762@gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "*******"
.Update
End With

' ========(( below is the code i want to find and store user and pass ))

Set info = Worksheets("AdminPanel2").Range("I11:I80").Find( _
What:=Me.txt_pass.Value, LookIn:=xlFormulas)

If Not info Is Nothing Then

   info.Parent.Activate
        info.Offset(0, 1).Select
        NUser = ActiveCell.Text            
 MsgBox "That data was sent"

 Else

MsgBox "That data was not found."

End If

'===========(( below code i want to recall it in body of the email ))

With cdomsg
.To = info
.From = "dash32762@gmail.com"
.Subject = "Restore information"
.TextBody = Hello youur username is NUser your password is NPass
.send
End With
Set cdomsg = Nothing
End Function

这是我要修改的代码:

 ' ========(( below is the code i want to find and store user and pass ))

Set info = Worksheets("AdminPanel2").Range("I11:I80").Find( _
What:=Me.txt_pass.Value, LookIn:=xlFormulas)

If Not info Is Nothing Then

   info.Parent.Activate
        info.Offset(0, 1).Select
        NUser = ActiveCell.Text            
 MsgBox "That data was sent"

 Else

MsgBox "That data was not found."

End If

在一封电子邮件中发送电子邮件和密码非常糟糕。将电子邮件和密码隐藏起来 Excel sheet 更糟。这真的不是它的完成方式,如果这不是一些学校项目,你可能会在工作中遇到很多问题。最好的做法是不要保留密码,而是保留its hash。并且不发送旧密码,而是创建一个新密码。


综上所述,.TextBody 应该是一个在变量之间带有 & 的字符串,如下所示:

With cdomsg
    .To = info
    .From = "dash32762@gmail.com"
    .Subject = "Restore information"
    .TextBody = "Hello your username is" & NUser & " your password is" & NPass
    .Send
End With

关于你问题中的部分:

With Worksheets("AdminPanel2").Range("I11:I80")
    Set info = .Find(What:=Me.txt_pass.Value, LookIn:=xlValues, LookAt:=xlWhole)
End With

If Not info Is Nothing Then
    NUser = info.Offset(0, 1)
    MsgBox "That data was sent for user " & info
Else
    MsgBox "That data was not found."
End If