how to make auto message reply with vba ?

amo

Board Regular
Joined
Apr 14, 2020
Messages
141
Office Version
  1. 2010
Platform
  1. Windows
how to make auto message reply with vba ??
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
I think we are going to need a bit more details than that!

Pleaase provide the following:
- What should "trigger" this message to run?
- What do you want this message to say?
 
Upvote 0
I think we are going to need a bit more details than that!

Pleaase provide the following:
- What should "trigger" this message to run?
- What do you want this message to say?
@Joe4

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:
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
 
Upvote 0
Try changing this line:
VBA Code:
            If strLookup = True Then
to this:
VBA Code:
            If strLookup <> "" Then
 
Upvote 0
Try changing this line:
VBA Code:
            If strLookup = True Then
to this:
VBA Code:
            If strLookup <> "" Then
thank you for the response
I tried but still failed
 
Upvote 0
Fail how exactly? Please provide details ("it does not work or it fails" is not enough information for us to help you).
Please explain exactly what is happening, and any error messages.

I cannot run your code, as you are making some references to some things which I am unfamiliar with (i.e. Selenium.ChromeDriver). I suspect that you either had to select some additional VB libraries or are using some add-ins. However, the way your code was working before was it was always going to go to the first (TRUE) clause of your IF...THEN block. I changed it so if the VLOOKUP does not return anything, it will then go to the ELSE portion of the IF...THEN block.
 
Upvote 0

Forum statistics

Threads
1,215,106
Messages
6,123,124
Members
449,097
Latest member
mlckr

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top