【问题标题】:Find two cells values in hidden sheet and store as string在隐藏表中查找两个单元格值并存储为字符串
【发布时间】:2019-04-02 07:53:38
【问题描述】:

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

正如您在下面看到的,这是一个隐藏的表格,其中包含一个包含有关注册客户的信息的表格,因此当我们收到与(用户名)和(密码)匹配的电子邮件时,将存储为字符串((!!无需激活或看到这张纸!!))

这是我当前的代码:

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

【问题讨论】:

  • 酷仪表板!
  • @BOB 谢谢!很高兴你喜欢它
  • 我建议你在截图中隐藏那些电子邮件和密码,以防万一。
  • @FoxfireAndBurnsAndBurns 感谢您的关心,它甚至不是真正的密码,只是随机的

标签: excel vba string forgot-password


【解决方案1】:

在一封电子邮件中发送电子邮件和密码非常糟糕。将电子邮件和密码保存在隐藏的 Excel 工作表中更糟糕。这真的不是如何完成的,如果这不是一些学校项目,你可能会在工作中遇到很多问题。最佳做法不是保留密码,而是保留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

【讨论】:

  • 是的,我知道它根本没有保存,它实际上是一个大学项目,我希望它保持原样,仅供参考,我做了几个基本的安全措施来保护我的 vba 代码并隐藏工作表标签完全。
  • @Fadi - 你的项目,你的规则。
  • 表格不代表电子邮件密码,只是我自己的注册表单使用我的excel项目的表格
  • 非常感谢,我知道这是一个简单的代码,但没有您的帮助无法解决:)
猜你喜欢
  • 2017-09-03
  • 1970-01-01
  • 1970-01-01
  • 2021-02-11
  • 1970-01-01
  • 2018-07-23
  • 1970-01-01
  • 2019-08-04
  • 2020-02-22
相关资源
最近更新 更多