Input Value from Excel to Browser Input Boxes.

noveske

Board Regular
Joined
Apr 15, 2022
Messages
120
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
  3. Web
This one seems simple, but has me going in circles.
Looking for a way to enter values to input boxes on an open Microsoft Edge Browser page without Selenium references.
Values are going into a column. Worked well for an open .pdf file.

Requirements:
1. Enter starting number to B1.
2. Enter number of total values needed to B3.
3. The destination window is already open and first input box is activated. Script identifies the browser window by name.
4. Script enters first value to input box.
5. Go to next box.
6. Script enters value + 1.
7. Repeat until number of total values is met.

Problems:
Base script works, I thought that it was lag somewhere that was throwing the tab key out of line. Attempt to add .01 second delay between the tab keys.
Then realize the real issue is sometimes randomly there will be a checkbox in a few rows. So it throw off tab navigation.

Attempts:
I am not able to add Selenium references. If Selenium is installed on one machine and added to the Workbook does every machine that utilizes the workbook need it installed or is it carried by the workbook?

Came across CDP (GitHub - longvh211/Chromium-Automation-with-CDP-for-VBA: A method to directly automate Chromium-based web browsers, such as Chrome, Edge, and Firefox, using VBA for Office applications by following the Chrome DevTools Protocol framework.)
  • Was able to have it identify Edge when opening a new browser instance. But it would always close open windows.
  • Could not get it to identify, recognize and attach to an existing open window.
Have script identify next empty box by column. Runs and adds to the first box, then does not continue. This script will be the second attached. Last script.

Tried by input id, but I think that required installing references not available to me due to workstation restrictions.

I have tried multiple different ways and have been unsuccessful. Script below has been the most successful. But I run into an issue when there is a random check box that's populated.
Example: If it is to repeat and have 15 numbers, it gets through about 6 before sendKey tab breaks and ends up out of line.

1692999853259.png


VBA Code:
Sub SendBrowser()
    Dim startValue As Double
    Dim repeatCount As Long
    Dim i As Long
   
    ' Read values from cells
    startValue = CDbl(Range("B1").Value)
    repeatCount = CLng(Range("B3").Value)
   
    ' Wait for 5 seconds
    Application.Wait Now + TimeValue("00:00:05")
   
    ' Loop through and send keys with tab
    For i = 1 To repeatCount
        On Error Resume Next
        AppActivate "Schedule"
        On Error GoTo 0
       
        If Err.Number <> 0 Then
            MsgBox "Application 'Schedule' not found!"
            Exit Sub
        End If
       
        SendKeys CStr(startValue), True
        WaitMillis 100 ' Wait for 100 milliseconds
        SendKeys "{TAB}", True
        WaitMillis 100 ' Wait for 100 milliseconds
        SendKeys "{TAB}", True
        WaitMillis 100 ' Wait for 100 milliseconds
        SendKeys "{TAB}", True
       
        startValue = startValue + 1
    Next i
End Sub

Sub WaitMillis(milliseconds As Long)
    Dim startTime As Double
    startTime = Timer
    Do While Timer < startTime + (milliseconds / 1000)
        DoEvents
    Loop
End Sub



VBA Code:
Sub SendBrowser()
    Dim startValue As Double
    Dim repeatCount As Long
    Dim i As Long
   
    ' Read values from cells
    startValue = CDbl(Range("B1").value)
    repeatCount = CLng(Range("B3").value)
   
    ' Wait for 5 seconds
    Application.Wait Now + TimeValue("00:00:05")
   
    ' Loop through and send keys to input boxes
    For i = 1 To repeatCount
        On Error Resume Next
        AppActivate "Schedule"
        On Error GoTo 0
       
        If Err.Number <> 0 Then
            MsgBox "Application 'Schedule' not found!"
            Exit Sub
        End If
       
        SendKeys CStr(startValue), True
       
        ' Find and activate the next empty input box
        FindNextEmptyInputBox
       
        startValue = startValue + 1
    Next i
End Sub

Sub FindNextEmptyInputBox()
    Dim activeCell As Range
    Dim inputColumn As Range
    Dim emptyCell As Range
   
    Set inputColumn = Columns(6) ' Column index 6 corresponds to column "F"
   
    For Each activeCell In inputColumn.Cells
        If activeCell.value = "" Then
            activeCell.Activate
            Exit For
        End If
    Next activeCell
End Sub
 
Last edited by a moderator:

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Update:
Was able to get this working with: GitHub - longvh211/Edge-IE-Mode-Automation-with-IES-for-VBA

Input boxes in the column would be sorted after being generated. So they would be out of order. Instead of number order, I was able to get this to inset into the next available input box beginning with Schedul_txt. So instead of sendKey [tab], this targets the input boxes directly.

To make this work, you do need to set the title target of the Edge window.
You also need the core module from the link above.

Edge automation works without Selenium.

VBA Code:
Sub Input()
    Dim startValue As Double
    Dim repeatCount As Long
    Dim i As Long
   
    startValue = CDbl(Range("B1").Value)
    repeatCount = CLng(Range("B3").Value)

    titleToFind = "Scheduled"
    Set ieDoc = GetEdgeIeDOM(titleToFind)
    If ieDoc Is Nothing Then
        MsgBox "The webpage cannot be found on Edge IE Mode! Has it been loaded under Edge IE Mode?"
        End
    End If
   
    For i = 0 To repeatCount - 1
        Dim inputBoxes As Object
        Set inputBoxes = ieDoc.querySelectorAll("[id^='Schedule_txt']")
       
        If inputBoxes.Length > i Then
            inputBoxes.Item(i).Value = startValue
            startValue = startValue + 1 ' Increase startValue by 1
        Else
            MsgBox "No more input boxes with the specified ID pattern found."
            Exit Sub
        End If
    Next i
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,224,813
Messages
6,181,107
Members
453,021
Latest member
Justyna P

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