a good afternoon
I tried to make autoreplay with vlookup and it worked perfectly
but I want if the message is not found in the data base ,, it sends a certain message, namely "Sorry, Message not found"
The problem is in the message not found, can't work
this is my code
I tried to make autoreplay with vlookup and it worked perfectly
but I want if the message is not found in the data base ,, it sends a certain message, namely "Sorry, Message not found"
The problem is in the message not found, can't work
this is my code
VBA Code:
Public Sub Read()
On Error Resume Next
Dim strMessage As String
Dim strSplit As Variant
Dim strLookup As String
Dim strReply As String
Dim strNewLine As Variant
Dim rw As Long
Dim iRow As Long
Set ch = New Selenium.ChromeDriver
Set by = New Selenium.by
ch.AddArgument ("user-data-dir-" & strlocal)
ch.Start
ch.Get "https://www.example.com"
iRow = Sheets("ChatLog").UsedRange.Rows.Count
ch.FindElementByClass(NewMessage).Click
strMessage = ch.FindElementsByClass(MessageList).Text
strSplit = Split(strMessage, "#")
strLookup = Application.WorksheetFunction.VLookup(strSplit(0), Sheets("AutoReply").Range("A:C"), 2, 0)
If strLookup = True Then
strReply = Application.WorksheetFunction.VLookup(strSplit(0), Sheets("AutoReply").Range("A:C"), 2, 0)
strNewLine = Split(strReply, vbLf)
For rw = 0 To UBound(strNewLine, 1)
ch.FindElementByXPath(ChatBox).SendKeys strNewLine(rw) & ch.Keys.Shift & ch.Keys.Enter & ch.Keys.LeftShift
Next rw
ch.SendKeys ch.Keys.Enter
ch.FindElementsByClass(FindChat)(1).Click
Else
strReply = "Sorry, Message not found"
strNewLine = Split(strReply, vbLf)
For rw = 0 To UBound(strNewLine, 1)
ch.FindElementByXPath(ChatBox).SendKeys strNewLine(rw) & ch.Keys.Shift & ch.Keys.Enter & ch.Keys.LeftShift
Next rw
ch.SendKeys ch.Keys.Enter
ch.FindElementsByClass(FindChat)(1).Click
End If
End Sub