Consulting

Results 1 to 9 of 9

Thread: Failed to run codes from txt file

  1. #1
    VBAX Newbie
    Joined
    Oct 2023
    Posts
    4
    Location

    Failed to run codes from txt file

    I know very little in programming. I have succeeded in using Selenium ChomeDrvier to control an existing instance of Chrome using the codes below in Excel VBA.

    Option Explicit
    
    Public Mychrome As Selenium.ChromeDriver
    Public DebuggerPort As String
    
    Sub getportnum()
    Dim Dict_Capib As Variant
    Set Mychrome = New Selenium.ChromeDriver
    Mychrome.Get "https://bet.hkjc.com/racing/pages/odds_wpq.aspx?lang=ch"
    Dict_Capib = Mychrome.Manage.Capabilities.Values
    DebuggerPort = Mychrome.Manage.Capabilities("goog:chromeOptions").Item("debuggerAddress")
    End Sub

    I use the Macro below to input data to the web page and it works fine.

    Sub copyodd()
    DebuggerPort = Mychrome.Manage.Capabilities("goog:chromeOptions").Item("debuggerAddress")
    Mychrome.SetCapability "debuggerAddress", "localhost:" & DebuggerPort
    Mychrome.FindElementById("qb_QIN_2_3").Click
    Mychrome.FindElementById("inputAmount0").ClickDouble
    Mychrome.FindElementById("inputAmount0").Sendkeys "10"
    End Sub
    However, when I try to run the same 3 lines in red above from a text file using the codes below, it does not work. Can someone help?


    Sub copyodd()
    DebuggerPort = Mychrome.Manage.Capabilities("goog:chromeOptions").Item("debuggerAddress")
    Mychrome.SetCapability "debuggerAddress", "localhost:" & DebuggerPort
    RunCodeFromFile
    End Sub
    
    Sub RunCodeFromFile()
    Dim FilePath As String
    Dim FileContent As String
    Dim CodeLines() As String
    Dim i As Long
    Dim LineContent As String ' Declare LineContent variable
    ' Specify the path to the text file
    FilePath = "C:\Horse\buyhorse.txt"
    ' Check if the file exists
    If Not Dir(FilePath) = "" Then
        ' Read the content of the text file
        Open FilePath For Input As #1
        Do Until EOF(1)
            Line Input #1, LineContent
            FileContent = FileContent & LineContent & vbCrLf
        Loop
        Close #1
        ' Split the content into lines
        CodeLines = Split(FileContent, vbCrLf)
        ' Execute each line of code
        For i = LBound(CodeLines) To UBound(CodeLines)
            On Error Resume Next
            Application.Run CodeLines(i)
            On Error GoTo 0
        Next i
    Else
        MsgBox "The file does not exist: " & FilePath
    End If
    End Sub
    I have posted this to the MrExcel.com forum https://www.mrexcel.com/board/thread...-file.1246367/
    Last edited by Aussiebear; 10-04-2023 at 02:24 PM. Reason: Added code tags and added indicator linked thread

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    Welcome to VBAX kyk8898. When posting codes to this forum please wrap them in Code tags as per the first line in my signature. Secondly, I would refer you to the cross posting issue. If you wish to cross post, feel free to do so, however if you multiple post within a couple of hours then you will quickly gain a poor reputation and very few people will assist you. The links you initially posted at the bottom of your thread only leads to a register for the forum, not the thread. I have corrected both the code tags and the link for you on this occasion.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    VBAX Regular
    Joined
    Sep 2023
    Posts
    97
    Location
    Can you show the contents of C:\Horse\buyhorse.txt?

    You are just wanting to replace the hardcoded values found here
    Sub copyodd()DebuggerPort = Mychrome.Manage.Capabilities("goog:chromeOptions").Item("debuggerAddress")
    Mychrome.SetCapability "debuggerAddress", "localhost:" & DebuggerPort
    Mychrome.FindElementById("qb_QIN_2_3").Click
    Mychrome.FindElementById("inputAmount0").ClickDouble
    Mychrome.FindElementById("inputAmount0").Sendkeys "10" 
    
    End Sub
    with the values that are stored in the text file? If this is the case, and the text file looks like:

    qb_QIN_2_3
    inputAmount0

    then I would so something like:
    Function GetTextFileData() as Variant     Dim FilePath As String
        Dim FileData(2) as String 
        Dim FileLineCount as Int
        Dim LineContent as String 
    
        ' Specify the path to the text file
        FilePath = "C:\Horse\buyhorse.txt"
    
        FileLineCount = 0
    
        Open FilePath For Input As #1
        Do Until EOF(1)
            Line Input #1, LineContent
            FileData(FileLineCount) = LineContent
            FileLineCount = FileLineCount + 1
        Loop
        Close #1
    
        GetTextFileData = FileData
    End Function 
    
    
    Sub copyodd()
        DebuggerPort = Mychrome.Manage.Capabilities("goog:chromeOptions").Item("debuggerAddress")
        Mychrome.SetCapability "debuggerAddress", "localhost:" & DebuggerPort
    
        Dim TextFileData() as String
    
        TextFileData = GetTextFileData()
    
        Mychrome.FindElementById(TextFileData(0)).Click
        Mychrome.FindElementById(TextFileData(1)).ClickDouble
        Mychrome.FindElementById(TextFileData(1)).Sendkeys "10"
    
    End Sub
    This code is untested as I just free typed it here.
    Edit: fixed typo

  4. #4
    VBAX Newbie
    Joined
    Oct 2023
    Posts
    4
    Location
    Thanks jdelano. Below is the content of the txt file. I just need to run all the lines in the text file.

    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    Mychrome.FindElementById("qb_QIN_2_3").Click
    Mychrome.FindElementById("inputAmount0").ClickDouble
    Mychrome.FindElementById("inputAmount0").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_2_4").Click
    Mychrome.FindElementById("inputAmount1").ClickDouble
    Mychrome.FindElementById("inputAmount1").Sendkeys "10"
    '
    '
    '
    '
    '
    '
    Mychrome.FindElementById("qb_QIN_2_7").Click
    Mychrome.FindElementById("inputAmount2").ClickDouble
    Mychrome.FindElementById("inputAmount2").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_2_8").Click
    Mychrome.FindElementById("inputAmount3").ClickDouble
    Mychrome.FindElementById("inputAmount3").Sendkeys "10"
    '
    '
    '
    Mychrome.FindElementById("qb_QIN_2_10").Click
    Mychrome.FindElementById("inputAmount4").ClickDouble
    Mychrome.FindElementById("inputAmount4").Sendkeys "10"
    '
    '
    '
    Mychrome.FindElementById("qb_QIN_2_12").Click
    Mychrome.FindElementById("inputAmount5").ClickDouble
    Mychrome.FindElementById("inputAmount5").Sendkeys "10"
    '
    '
    '
    '
    '
    '
    Mychrome.FindElementById("qb_QIN_3_4").Click
    Mychrome.FindElementById("inputAmount6").ClickDouble
    Mychrome.FindElementById("inputAmount6").Sendkeys "10"
    '
    '
    '
    '
    '
    '
    Mychrome.FindElementById("qb_QIN_3_7").Click
    Mychrome.FindElementById("inputAmount7").ClickDouble
    Mychrome.FindElementById("inputAmount7").Sendkeys "20"
    Mychrome.FindElementById("qb_QIN_3_8").Click
    Mychrome.FindElementById("inputAmount8").ClickDouble
    Mychrome.FindElementById("inputAmount8").Sendkeys "10"
    '
    '
    '
    Mychrome.FindElementById("qb_QIN_3_10").Click
    Mychrome.FindElementById("inputAmount9").ClickDouble
    Mychrome.FindElementById("inputAmount9").Sendkeys "10"
    '
    '
    '
    Mychrome.FindElementById("qb_QIN_3_12").Click
    Mychrome.FindElementById("inputAmount10").ClickDouble
    Mychrome.FindElementById("inputAmount10").Sendkeys "10"
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    Mychrome.FindElementById("qb_QIN_4_7").Click
    Mychrome.FindElementById("inputAmount11").ClickDouble
    Mychrome.FindElementById("inputAmount11").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_4_8").Click
    Mychrome.FindElementById("inputAmount12").ClickDouble
    Mychrome.FindElementById("inputAmount12").Sendkeys "10"
    '
    '
    '
    Mychrome.FindElementById("qb_QIN_4_10").Click
    Mychrome.FindElementById("inputAmount13").ClickDouble
    Mychrome.FindElementById("inputAmount13").Sendkeys "10"
    '
    '
    '
    Mychrome.FindElementById("qb_QIN_4_12").Click
    Mychrome.FindElementById("inputAmount14").ClickDouble
    Mychrome.FindElementById("inputAmount14").Sendkeys "10"
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    Mychrome.FindElementById("qb_QIN_7_8").Click
    Mychrome.FindElementById("inputAmount15").ClickDouble
    Mychrome.FindElementById("inputAmount15").Sendkeys "20"
    '
    '
    '
    Mychrome.FindElementById("qb_QIN_7_10").Click
    Mychrome.FindElementById("inputAmount16").ClickDouble
    Mychrome.FindElementById("inputAmount16").Sendkeys "20"
    '
    '
    '
    Mychrome.FindElementById("qb_QIN_7_12").Click
    Mychrome.FindElementById("inputAmount17").ClickDouble
    Mychrome.FindElementById("inputAmount17").Sendkeys "20"
    '
    '
    '
    '
    '
    '
    '
    '
    '
    Mychrome.FindElementById("qb_QIN_8_10").Click
    Mychrome.FindElementById("inputAmount18").ClickDouble
    Mychrome.FindElementById("inputAmount18").Sendkeys "10"
    '
    '
    '
    Mychrome.FindElementById("qb_QIN_8_12").Click
    Mychrome.FindElementById("inputAmount19").ClickDouble
    Mychrome.FindElementById("inputAmount19").Sendkeys "10"
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    Mychrome.FindElementById("qb_QIN_10_12").Click
    Mychrome.FindElementById("inputAmount20").ClickDouble
    Mychrome.FindElementById("inputAmount20").Sendkeys "10"
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    Mychrome.FindElementById("bsSendPreviewButton").Click

  5. #5
    VBAX Regular
    Joined
    Sep 2023
    Posts
    97
    Location
    You're welcome, happy to help out.

    Ok, given this data I would structure the text file like this:
    qb_QIN_2_3, inputAmount0
    qb_QIN_2_4, inputAmount1
    qb_QIN_2_8, inputAmount3
    qb_QIN_2_10, inputAmount4
    then I would use a 2-dimensional array to load the data and loop through that array to run your commands. So, the new code would look like this:
    *** note: I preferer using the FileSystemObject when dealing with text files, go into Tools > References > Find Microsoft Scripting Runtime and check it.

    See the attachment to see how the code reads the file and then creates an array from the data.

    Function GetTextFileData() as Variant
        Dim FilePath As String
        Dim FileData(3, 1) As String   ' modify the first number to match the number of lines in the text file minus 1 (because arrays start at 0)
        Dim FileLineCount As Integer
        Dim LineContent As String
        
        Dim fs As FileSystemObject
        Dim TextFile As TextStream
        
        ' Specify the path to the text file
        FilePath = "C:\Horse\buyhorse.txt"
        
        Set fs = New FileSystemObject
        Set TextFile = fs.OpenTextFile(FilePath, ForReading)
            
        FileLineCount = 0
        
        Do While Not TextFile.AtEndOfStream
            LineContent = TextFile.ReadLine
            If Len(LineContent) = 0 then Exit Do  ' just in case there is an empty line at the end of the file
    
            ' when the line is read the two values are separated by a comma, use the split function to grab each value.
            FileData(FileLineCount, 0) = Split(LineContent, ",")(0)
            FileData(FileLineCount, 1) = Split(LineContent, ",")(1)
            FileLineCount = FileLineCount + 1
        Loop
        TextFile.Close
    
        GetTextFileData = FileData
    End Function
    
    Sub copyodd()
        DebuggerPort = Mychrome.Manage.Capabilities("goog:chromeOptions").Item("debuggerAddress")
        Mychrome.SetCapability "debuggerAddress", "localhost:" & DebuggerPort
        
        Dim TextFileData() as String
        Dim i as integer 
        
        TextFileData = GetTextFileData()
        
        For i = 0 To Ubound(TextFileData)
            Mychrome.FindElementById(TextFileData(i, 0)).Click
            Mychrome.FindElementById(TextFileData(i, 1)).ClickDouble
            Mychrome.FindElementById(TextFileData(i, 1)).Sendkeys "10"
            DoEvents   ' this allow Excel to catchup processing commands
        Next i
        
    End Sub
    EDIT:2 (added Split function link)
    Here a few links to checkout:
    Using arrays (VBA) | Microsoft Learn
    Split function (Visual Basic for Applications) | Microsoft Learn
    Attached Images Attached Images

  6. #6
    VBAX Newbie
    Joined
    Oct 2023
    Posts
    4
    Location
    Thanks for the prompt reply. However, I would like to explain a bit more on my text file. There are altogether 274 lines in the text file and the total number does not change.

    Depending on the situation, I may not need to run certain lines in the file and in such case they are turned off and are denoted as ' (single quote) as seen above in #4. Some lines in the code below are turned off.

    The codes can be perceived as grouped in a set of 3 lines. For examaple, if the 1st line (italic & undeline) in the set does not need to be run, the 2nd & 3rd lines (underline) will also be turned off.

    The inputAmount starts from inputAmount0 and changes depending on whether the previous lines are turned on or off.

    Hope my explanation can help.

    Mychrome.FindElementById("qb_QIN_1_2").Click
    Mychrome.FindElementById("inputAmount0").ClickDouble
    Mychrome.FindElementById("inputAmount0").Sendkeys "30"
    Mychrome.FindElementById("qb_QIN_1_3").Click
    Mychrome.FindElementById("inputAmount1").ClickDouble
    Mychrome.FindElementById("inputAmount1").Sendkeys "30"
    Mychrome.FindElementById("qb_QIN_1_4").Click
    Mychrome.FindElementById("inputAmount2").ClickDouble
    Mychrome.FindElementById("inputAmount2").Sendkeys "80"
    Mychrome.FindElementById("qb_QIN_1_5").Click
    Mychrome.FindElementById("inputAmount3").ClickDouble
    Mychrome.FindElementById("inputAmount3").Sendkeys "70"
    Mychrome.FindElementById("qb_QIN_1_6").Click
    Mychrome.FindElementById("inputAmount4").ClickDouble
    Mychrome.FindElementById("inputAmount4").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_1_7").Click
    Mychrome.FindElementById("inputAmount5").ClickDouble
    Mychrome.FindElementById("inputAmount5").Sendkeys "60"
    Mychrome.FindElementById("qb_QIN_1_8").Click
    Mychrome.FindElementById("inputAmount6").ClickDouble
    Mychrome.FindElementById("inputAmount6").Sendkeys "30"
    Mychrome.FindElementById("qb_QIN_1_9").Click
    Mychrome.FindElementById("inputAmount7").ClickDouble
    Mychrome.FindElementById("inputAmount7").Sendkeys "40"
    Mychrome.FindElementById("qb_QIN_1_10").Click
    Mychrome.FindElementById("inputAmount8").ClickDouble
    Mychrome.FindElementById("inputAmount8").Sendkeys "80"
    Mychrome.FindElementById("qb_QIN_1_11").Click
    Mychrome.FindElementById("inputAmount9").ClickDouble
    Mychrome.FindElementById("inputAmount9").Sendkeys "20"
    Mychrome.FindElementById("qb_QIN_1_12").Click
    Mychrome.FindElementById("inputAmount10").ClickDouble
    Mychrome.FindElementById("inputAmount10").Sendkeys "70"
    '
    '
    '
    '
    '
    '
    Mychrome.FindElementById("qb_QIN_2_3").Click
    Mychrome.FindElementById("inputAmount11").ClickDouble
    Mychrome.FindElementById("inputAmount11").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_2_4").Click
    Mychrome.FindElementById("inputAmount12").ClickDouble
    Mychrome.FindElementById("inputAmount12").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_2_5").Click
    Mychrome.FindElementById("inputAmount13").ClickDouble
    Mychrome.FindElementById("inputAmount13").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_2_6").Click
    Mychrome.FindElementById("inputAmount14").ClickDouble
    Mychrome.FindElementById("inputAmount14").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_2_7").Click
    Mychrome.FindElementById("inputAmount15").ClickDouble
    Mychrome.FindElementById("inputAmount15").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_2_8").Click
    Mychrome.FindElementById("inputAmount16").ClickDouble
    Mychrome.FindElementById("inputAmount16").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_2_9").Click
    Mychrome.FindElementById("inputAmount17").ClickDouble
    Mychrome.FindElementById("inputAmount17").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_2_10").Click
    Mychrome.FindElementById("inputAmount18").ClickDouble
    Mychrome.FindElementById("inputAmount18").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_2_11").Click
    Mychrome.FindElementById("inputAmount19").ClickDouble
    Mychrome.FindElementById("inputAmount19").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_2_12").Click
    Mychrome.FindElementById("inputAmount20").ClickDouble
    Mychrome.FindElementById("inputAmount20").Sendkeys "10"
    '
    '
    '
    '
    '
    '
    Mychrome.FindElementById("qb_QIN_3_4").Click
    Mychrome.FindElementById("inputAmount21").ClickDouble
    Mychrome.FindElementById("inputAmount21").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_3_5").Click
    Mychrome.FindElementById("inputAmount22").ClickDouble
    Mychrome.FindElementById("inputAmount22").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_3_6").Click
    Mychrome.FindElementById("inputAmount23").ClickDouble
    Mychrome.FindElementById("inputAmount23").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_3_7").Click
    Mychrome.FindElementById("inputAmount24").ClickDouble
    Mychrome.FindElementById("inputAmount24").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_3_8").Click
    Mychrome.FindElementById("inputAmount25").ClickDouble
    Mychrome.FindElementById("inputAmount25").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_3_9").Click
    Mychrome.FindElementById("inputAmount26").ClickDouble
    Mychrome.FindElementById("inputAmount26").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_3_10").Click
    Mychrome.FindElementById("inputAmount27").ClickDouble
    Mychrome.FindElementById("inputAmount27").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_3_11").Click
    Mychrome.FindElementById("inputAmount28").ClickDouble
    Mychrome.FindElementById("inputAmount28").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_3_12").Click
    Mychrome.FindElementById("inputAmount29").ClickDouble
    Mychrome.FindElementById("inputAmount29").Sendkeys "10"
    '
    '
    '
    '
    '
    '
    Mychrome.FindElementById("qb_QIN_4_5").Click
    Mychrome.FindElementById("inputAmount30").ClickDouble
    Mychrome.FindElementById("inputAmount30").Sendkeys "30"
    Mychrome.FindElementById("qb_QIN_4_6").Click
    Mychrome.FindElementById("inputAmount31").ClickDouble
    Mychrome.FindElementById("inputAmount31").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_4_7").Click
    Mychrome.FindElementById("inputAmount32").ClickDouble
    Mychrome.FindElementById("inputAmount32").Sendkeys "20"
    Mychrome.FindElementById("qb_QIN_4_8").Click
    Mychrome.FindElementById("inputAmount33").ClickDouble
    Mychrome.FindElementById("inputAmount33").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_4_9").Click
    Mychrome.FindElementById("inputAmount34").ClickDouble
    Mychrome.FindElementById("inputAmount34").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_4_10").Click
    Mychrome.FindElementById("inputAmount35").ClickDouble
    Mychrome.FindElementById("inputAmount35").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_4_11").Click
    Mychrome.FindElementById("inputAmount36").ClickDouble
    Mychrome.FindElementById("inputAmount36").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_4_12").Click
    Mychrome.FindElementById("inputAmount37").ClickDouble
    Mychrome.FindElementById("inputAmount37").Sendkeys "10"
    '
    '
    '
    '
    '
    '
    Mychrome.FindElementById("qb_QIN_5_6").Click
    Mychrome.FindElementById("inputAmount38").ClickDouble
    Mychrome.FindElementById("inputAmount38").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_5_7").Click
    Mychrome.FindElementById("inputAmount39").ClickDouble
    Mychrome.FindElementById("inputAmount39").Sendkeys "30"
    Mychrome.FindElementById("qb_QIN_5_8").Click
    Mychrome.FindElementById("inputAmount40").ClickDouble
    Mychrome.FindElementById("inputAmount40").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_5_9").Click
    Mychrome.FindElementById("inputAmount41").ClickDouble
    Mychrome.FindElementById("inputAmount41").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_5_10").Click
    Mychrome.FindElementById("inputAmount42").ClickDouble
    Mychrome.FindElementById("inputAmount42").Sendkeys "20"
    Mychrome.FindElementById("qb_QIN_5_11").Click
    Mychrome.FindElementById("inputAmount43").ClickDouble
    Mychrome.FindElementById("inputAmount43").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_5_12").Click
    Mychrome.FindElementById("inputAmount44").ClickDouble
    Mychrome.FindElementById("inputAmount44").Sendkeys "20"
    '
    '
    '
    '
    '
    '
    Mychrome.FindElementById("qb_QIN_6_7").Click
    Mychrome.FindElementById("inputAmount45").ClickDouble
    Mychrome.FindElementById("inputAmount45").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_6_8").Click
    Mychrome.FindElementById("inputAmount46").ClickDouble
    Mychrome.FindElementById("inputAmount46").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_6_9").Click
    Mychrome.FindElementById("inputAmount47").ClickDouble
    Mychrome.FindElementById("inputAmount47").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_6_10").Click
    Mychrome.FindElementById("inputAmount48").ClickDouble
    Mychrome.FindElementById("inputAmount48").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_6_11").Click
    Mychrome.FindElementById("inputAmount49").ClickDouble
    Mychrome.FindElementById("inputAmount49").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_6_12").Click
    Mychrome.FindElementById("inputAmount50").ClickDouble
    Mychrome.FindElementById("inputAmount50").Sendkeys "10"
    '
    '
    '
    '
    '
    '
    Mychrome.FindElementById("qb_QIN_7_8").Click
    Mychrome.FindElementById("inputAmount51").ClickDouble
    Mychrome.FindElementById("inputAmount51").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_7_9").Click
    Mychrome.FindElementById("inputAmount52").ClickDouble
    Mychrome.FindElementById("inputAmount52").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_7_10").Click
    Mychrome.FindElementById("inputAmount53").ClickDouble
    Mychrome.FindElementById("inputAmount53").Sendkeys "20"
    Mychrome.FindElementById("qb_QIN_7_11").Click
    Mychrome.FindElementById("inputAmount54").ClickDouble
    Mychrome.FindElementById("inputAmount54").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_7_12").Click
    Mychrome.FindElementById("inputAmount55").ClickDouble
    Mychrome.FindElementById("inputAmount55").Sendkeys "20"
    '
    '
    '
    '
    '
    '
    Mychrome.FindElementById("qb_QIN_8_9").Click
    Mychrome.FindElementById("inputAmount56").ClickDouble
    Mychrome.FindElementById("inputAmount56").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_8_10").Click
    Mychrome.FindElementById("inputAmount57").ClickDouble
    Mychrome.FindElementById("inputAmount57").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_8_11").Click
    Mychrome.FindElementById("inputAmount58").ClickDouble
    Mychrome.FindElementById("inputAmount58").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_8_12").Click
    Mychrome.FindElementById("inputAmount59").ClickDouble
    Mychrome.FindElementById("inputAmount59").Sendkeys "10"
    '
    '
    '
    '
    '
    '
    Mychrome.FindElementById("qb_QIN_9_10").Click
    Mychrome.FindElementById("inputAmount60").ClickDouble
    Mychrome.FindElementById("inputAmount60").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_9_11").Click
    Mychrome.FindElementById("inputAmount61").ClickDouble
    Mychrome.FindElementById("inputAmount61").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_9_12").Click
    Mychrome.FindElementById("inputAmount62").ClickDouble
    Mychrome.FindElementById("inputAmount62").Sendkeys "10"
    '
    '
    '
    '
    '
    '
    Mychrome.FindElementById("qb_QIN_10_11").Click
    Mychrome.FindElementById("inputAmount63").ClickDouble
    Mychrome.FindElementById("inputAmount63").Sendkeys "10"
    Mychrome.FindElementById("qb_QIN_10_12").Click
    Mychrome.FindElementById("inputAmount64").ClickDouble
    Mychrome.FindElementById("inputAmount64").Sendkeys "10"
    '
    '
    '
    '
    '
    '
    Mychrome.FindElementById("qb_QIN_11_12").Click
    Mychrome.FindElementById("inputAmount65").ClickDouble
    Mychrome.FindElementById("inputAmount65").Sendkeys "10"
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '
    '

  7. #7
    VBAX Regular
    Joined
    Sep 2023
    Posts
    97
    Location
    I see, I would move this data from a text file to a sheet in your workbook. Let's say "InputData", then there is no need for reading the text file. Just loop that sheet. Add a column to indicate whether a row should be used or not. I used "Include", if there is a Yes in that cell then the row's data is used else it is skipped.


    Sub copyodd()
        DebuggerPort = Mychrome.Manage.Capabilities("goog:chromeOptions").Item("debuggerAddress")
        Mychrome.SetCapability "debuggerAddress", "localhost:" & DebuggerPort
        
        Dim i As Integer   
        Dim inputDataSheet As Worksheet
        
        Set inputDataSheet = ThisWorkbook.Sheets("InputData")
        
        For i = 2 To 276
            if inputDataSheet.cells(i,4) = "Yes" Then
                Mychrome.FindElementById(inputDataSheet.cells(i,1)).Click
                Mychrome.FindElementById(inputDataSheet.cells(i,2)).ClickDouble
                Mychrome.FindElementById(inputDataSheet.cells(i,2)).Sendkeys CStr(inputDataSheet.cells(i,3))
                DoEvents
            End If
        Next i
        
    End Sub
    edit: you may need the CStr() function to convert the numeric value to a string for the SendKeys method to work - edited the code above.
    Attached Images Attached Images

  8. #8
    VBAX Newbie
    Joined
    Oct 2023
    Posts
    4
    Location
    It works. Thank you so mcuh, jdelano.

  9. #9
    VBAX Regular
    Joined
    Sep 2023
    Posts
    97
    Location
    You're welcome, glad it is working for you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •