noveske
Board Regular
- Joined
- Apr 15, 2022
- Messages
- 120
- Office Version
- 365
- Platform
- Windows
- Mobile
- 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.)
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.
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.
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.
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: