Selenium Macro Pastes Data Successfully for Thousands of Iterations Before Giving “Echo is On”

I created a VBA macro that uses selenium to go to a website and pastes inputs in multiple fields and uploads some files by copying the file paths from the excel sheet. It has a for loop so it needs to do this thousands of times.

I used it on one of my computers and it worked perfectly for the first 20 times or so before it started to paste “echo is on” for one of the file paths instead of the file path on one of the iterations of the loop. Oddly, even on that iteration of the loop it pastes multiple other values successfully before doing this.

I tried the identical code on the same spreadsheet on a different computer and the problem seemed to disappear. I ran the macro for another 1,000 iterations and it worked flawlessly but then still started pasting the “echo is on” again for that same filepath cell.

Here is my code if that helps


Option Explicit

Dim MyBrowser As New Selenium.ChromeDriver

Sub SubmitTheHungryJPEGLoop()

Dim i
Dim strFilePath
Dim firstimageupload
Dim zipupload
Dim WshShell
Dim secondimageupload
Dim PinterestPin
Dim AddTitle
Dim AddDescription
Dim SubmissionCategory
Set MyBrowser = New Selenium.ChromeDriver
Dim iframeelement As WebElement
Dim noError As Boolean ' Define noError as a boolean variable

               
MyBrowser.Start baseUrl:="example.com"
MyBrowser.Get "https://example.com"
Application.Wait DateAdd("s", 35, Now)
MyBrowser.FindElementByXPath("/html/body/div[1]/header/div[1]/div[2]/div/div[2]/ul/li[1]/a[1]").Click
Application.Wait DateAdd("s", 3, Now)

MyBrowser.FindElementByXPath("/html/body/div[2]/div/div/div[1]/form/div[4]/input").SendKeys "myloginemail"
MyBrowser.FindElementByXPath("/html/body/div[2]/div/div/div[1]/form/div[5]/input").SendKeys "mypassword"

MyBrowser.FindElementByXPath("/html/body/div[2]/div/div/div[1]/form/div[7]/button").Click

For i = 4 To 10

linek:
noError = True
On Error GoTo linej:




AddTitle = Sheet1.Cells(i, 1).Value


AddDescription = Sheet1.Cells(i, 4).Value

firstimageupload = Sheet1.Cells(i, 2).Value

PinterestPin = Sheet1.Cells(i, 29).Value
SubmissionCategory = Sheet1.Cells(i, 22).Value

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "cmd.exe /c echo " & firstimageupload & "| clip", 0, True

Application.Wait DateAdd("s", 15, Now)
MyBrowser.Get "https://thehungryjpeg.com/add_product"

Application.Wait DateAdd("s", 20, Now)
MyBrowser.FindElementByXPath("/html/body/div[1]/div/section/form/div/div[1]/div[1]/div/div[1]/ul/li/div/div[2]/input").ClickAndHold


MyBrowser.FindElementByXPath("/html/body/div[1]/div/section/form/div/div[1]/div[1]/div/div[1]/ul/li/div/div[2]").Click

Application.Wait DateAdd("s", 2, Now)

WshShell.SendKeys "^{v}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{TAB}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "^{TAB}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{ENTER}"
Application.Wait DateAdd("s", 2, Now)


MyBrowser.FindElementByXPath("/html/body/div[1]/div/section/form/div/div[1]/div[2]/div/div[1]/input").SendKeys AddTitle

MyBrowser.FindElementByXPath("/html/body/div[1]/div/section/form/div/div[1]/div[2]/div/div[2]/div/div[1]/select").Click

WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "^{ENTER}"

If SubmissionCategory = "Shapes" Then
MyBrowser.FindElementByXPath("/html/body/div[1]/div/section/form/div/div[1]/div[2]/div/div[2]/div/div[2]/select").Click
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "^{ENTER}"
End If

If SubmissionCategory = "Quotes" Then
MyBrowser.FindElementByXPath("/html/body/div[1]/div/section/form/div/div[1]/div[2]/div/div[2]/div/div[2]/select").Click
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "^{ENTER}"
End If
If SubmissionCategory = "Animals" Then
MyBrowser.FindElementByXPath("/html/body/div[1]/div/section/form/div/div[1]/div[2]/div/div[2]/div/div[2]/select").Click
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "^{ENTER}"
End If
If SubmissionCategory = "Sublimation" Then
MyBrowser.FindElementByXPath("/html/body/div[1]/div/section/form/div/div[1]/div[2]/div/div[2]/div/div[2]/select").Click
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "^{ENTER}"
End If
If SubmissionCategory = "Travel" Then
MyBrowser.FindElementByXPath("/html/body/div[1]/div/section/form/div/div[1]/div[2]/div/div[2]/div/div[2]/select").Click
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "^{ENTER}"
End If
If SubmissionCategory = "Holiday" Then
MyBrowser.FindElementByXPath("/html/body/div[1]/div/section/form/div/div[1]/div[2]/div/div[2]/div/div[2]/select").Click
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "^{ENTER}"
End If
If SubmissionCategory = "People" Then
MyBrowser.FindElementByXPath("/html/body/div[1]/div/section/form/div/div[1]/div[2]/div/div[2]/div/div[2]/select").Click
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{DOWN}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "^{ENTER}"
End If
MyBrowser.FindElementByXPath("/html/body/div[1]/div/section/form/div/div[1]/div[2]/div/div[6]/div/div[14]/input").Click
MyBrowser.FindElementByXPath("/html/body/div[1]/div/section/form/div/div[1]/div[2]/div/div[6]/div/div[13]/input").Click
MyBrowser.FindElementByXPath("/html/body/div[1]/div/section/form/div/div[1]/div[2]/div/div[6]/div/div[4]/input").Click
MyBrowser.FindElementByXPath("/html/body/div[1]/div/section/form/div/div[1]/div[2]/div/div[6]/div/div[10]/input").Click

MyBrowser.FindElementByXPath("/html/body/div[1]/div/section/form/div/div[1]/div[2]/div/div[3]/div/input").SendKeys "2"


zipupload = Sheet1.Cells(i, 3).Value
MyBrowser.FindElementByXPath("/html/body/div[1]/div/section/form/div/div[1]/div[2]/div/div[7]/div/div/input").Click


MyBrowser.FindElementByXPath("/html/body/div[1]/div/section/form/div/div[1]/div[2]/div/div[9]/div").Click
WshShell.Run "cmd.exe /c echo " & zipupload & "| clip", 0, True
Application.Wait DateAdd("s", 2, Now)

WshShell.SendKeys "^{v}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{TAB}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "^{TAB}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{ENTER}"
Application.Wait DateAdd("s", 2, Now)

Set iframeelement = MyBrowser.FindElementByXPath("/html/body/div[1]/div/section/form/div/div[1]/div[1]/div/div[2]/div[1]/div/div/iframe")
MyBrowser.SwitchToFrame iframeelement

MyBrowser.FindElementByXPath("/html/body").SendKeys AddDescription
MyBrowser.SwitchToParentFrame
Application.Wait DateAdd("s", 4, Now)
MyBrowser.FindElementByXPath("/html/body/div[1]/div/section/form/div/div[2]/button[2]").Click
MyBrowser.FindElementByXPath("/html/body/div[1]/div/section/form/div/div[2]/button[2]").Click
WshShell.Run "cmd.exe /c echo " & firstimageupload & "| clip", 0, True

If noError Then ' Check if no error occurred
GoTo linel:
End If

linej:
On Error GoTo -1
WshShell.SendKeys "^{ENTER}"
Application.Wait DateAdd("s", 2, Now)
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{TAB}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "^{TAB}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "^{TAB}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{ENTER}"
Application.Wait DateAdd("s", 2, Now)
Application.Wait DateAdd("s", 10, Now)
WshShell.SendKeys "{TAB}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "^{TAB}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "^{TAB}"
Application.Wait DateAdd("s", 2, Now)
WshShell.SendKeys "{ENTER}"
GoTo linek:
linel:
Next
End Sub

















Does anyone have any thoughts on how to fix this? I did look at the posts under the “Review questions already on Stack Overflow to see if your question is a duplicate.” section to see if there was a solution, but those don’t seem to be about VBA and don’t talk about a situation where the program works for a while and then stops for some reason.

I tried testing on different computers and that worked for a bit. I also tried moving the section of the code higher up to see if that changed anything but it didn’t.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật