I developed a macro to fill fields in a web site, click a "validate" and "submit" button.
On my machine, with the Enterprise Edition, it runs as expected. I tested it a number of times.
I sent the macro to a field user, who has the Player Edition (same version number). The macro, runs through the login process and works until it starts entering data. When it runs the highlighted code below, the macro clears the web site and leaves a few links.
The code below is for updating the first field. It enters the value and then clicks the "ENTER" button. This particular website needs an "enter" or "tab" keystroke at this point to start a behind the scenes validation. (When it runs on my machine, there is a little validation message that pops up after the "ENTER" key is executed - just like it is supposed to. This isn’t happening with the Player Edition.)
Several different users, with the Player Edition have tried the macro, and the same thing happens; the website goes practically blank when the "ENTER" command is executed.
I have tried the following things:
Commented the code out – doesn’t work
Change the 0 to * - doesn’t work
Changed ENTER to TAB – doesn’t work – the macro enters } after TAB
I also looked at the emulation. When I run the macro, the bottom of the web site says “Emulating IE 10”. When the user runs the macro, the web site says “Emulating IE 11”. Could this be the cause of the different behavior? If so, is there a way to programmatically change it? Is there was way to force the macro to emulate IE 10 when the user runs the macro? I have two other iMacros that they use and this hasn’t been an issue before.
The extract code below is used to confirm that a value has been entered and validated and then the macro moves on to the next field.
IM = ""
IM = "CODE:"
IM = IM + "TAB T=2" + vbNewLine
IM = IM + "SET !TIMEOUT 1" + vbNewLine
IM = IM + "TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:editWarrantyform:repairOrderNumberId CONTENT=" & vRO(Y) + vbNewLine
iret = iim1.iimPlay(IM)
IM = ""
IM = "CODE:"
IM = IM + "TAB T=2" + vbNewLine
IM = IM + "SET !TIMEOUT 60" + vbNewLine
IM = IM + "DS CMD=KEY X=0 Y=0 CONTENT={ENTER}" + vbNewLine
iret = iim1.iimPlay(IM) **** MACRO ERRORS OUT WHEN THIS LINE IS EXECUTED
IM = ""
IM = "CODE:"
IM = IM + "TAB T=2" + vbNewLine
IM = IM + "SET !TIMEOUT 60" + vbNewLine
IM = IM + "TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:editWarrantyform:repairOrderNumberId EXTRACT=TXT" + vbNewLine
iret = iim1.iimPlay(IM)
vTmp = ""
vTmp = iim1.iimgetlastextract
vTmp = Replace(vTmp, "[EXTRACT]", "")
vTmp = Trim(vTmp)
Does the "ENTER" command work any different in the Player edition than in the Enterprise Edition? I have several other iMacro processes in this same macro and the field users say these run without any issues. I don't think the "ENTER" command is used in any of these other processes.
Turns out it was the IE emulation. On my machine (Enterprise Edition), the IE emulation was 10. On the user's machine (Player Edition), the IE emulation was 11. Once we switched the user's emulation to IE 10, the macro ran like it did on my machine....who knew....
Related
So in edge I F12, goto console and type in SM.Player.token and receive a value back, not sure what you call this - a javascript variable or function?
I've got a program that does various interactions with this page and whilst I can manually go into the console, retrieve this value and enter it into a text box in the app it would be nice to be able to automate this part of the process.
I tried :
Dim token As String = ""
Dim script As String = "document.getElementById('SM.Player.token')"
token = "" & WebView2.ExecuteScriptAsync(script).ToString
But that just returns :
"System.Threading.Tasks.Task`1[System.String]"
Anyone able to point me in the right direction?
I want to add a product number to a collection like this:
colData.Add marke.Value + " " + pn.Value (Range-Objekte)
Every time I start the macro it runs in Runtime Error 13.
If the product number is like 256-78979-0980 everything runs fine.
If the product number is like 8898686 the error occurs.
Writing CStr(pn.Value) doesn't solve the issue.
The only solution I found is to change the format of all PNs to type text.
Then I need to go in the cell and press "Enter" after that a sign appears on the cell stating that the number is recognized as text.
After that the macro works fine for this cell but not for the others.
How can I change my data to make it work with my macro?
Avoid using + for concatenation.
Try repalcing of
colData.Add marke.Value + " " + pn.Value
with
colData.Add marke.Value & " " & pn.Value
I made a few improvements to code that has been functioning without issues. On the development, the app runs with a problem. Installed on a test computer and it does not run unless I right click and run as administrator. The below code is where gets not running as Administrator.
The for loop is adding file names to a list. Administrator the program just ends no errors just quits. i counter gets to 3 of a total of 6 files. Never gets through to post the message "Did it make it here". But does post the message inside the for loop. i counts to 3. If run as admin then no issues. All file names are short and basic with no special characters. The files locations is Application.CommonAppDataPath. The loop is called from Form load.
Hoping someone could tell me what is going on.
Try
Selected_Machine = XMLReadSetting("Machine", "Selected", "Selexx")
For i = 0 To UBound(files)
MessageBox.Show("Here 2 i " & i & " File Name" & files(i))
cboMachine.Items.Add(IO.Path.GetFileNameWithoutExtension(files(i)))
If Selected_Machine = IO.Path.GetFileNameWithoutExtension(files(i)) Then
cboMachine.SelectedItem = IO.Path.GetFileNameWithoutExtension(files(i))
End If
Next
Catch err As SyntaxErrorException
MessageBox.Show(err.Message)
End Try
MessageBox.Show("Did it make it here?")
Found the issue. Inside the for loop it make a change that calls the text changed event of the list box. In the text changed event I write data to a settings file. The settings file did not have write access. Not sure how that happend but problem solved
Thank you all for the help.
I've created a form that works well with macros running in the background to validate data and then print the document to a specific printer on the network.
The key element of this process is a production number value which I would like to keep a running log of and display in a static status dialog window. In other words, a popup window similar to a MsgBox that would not interfere with other actions on the form, but float on top of the document.
Visual concept of this would be...
User could shift the window away from their work if needed. Close the window if they desired, but pragmatically I want to re-pop/refresh the data in the window each time the background macro completes.
I can't use MsgBox, because it forces a closure of the window before the user can continue working on the document. I just want this visible to the user so they know what was last worked on and the few prior to that.
Any idea what control I might be able to use, or switch to MsgBox that would allow the user to continue working?
Ken...
PS: I found this and am trying to find a way to make this work for me. So far I have managed to get to function in the manner I want, but the lingering issue is how to call this PS script and include the information I need to display.
Alternatives to MsgBox in VBScript - StackOverflow
PPS: I opted to go a slightly different route and release the form with a MsgBox that is displayed at the end of the macro. I describe this in the solution noted below.
Instead of using a MsgBox, please consider using a VBA Userform. They're not much more complicated to use than a MegBox, but you can set them to be Modeless. Modeless dialogs remain open on-screen while you work on the Word document. Here'is Microsoft's page on setting dialogs as Modal or Modeless: Show method
If you search on VBA modeless dialog, you'll find many other helpful pages on the subject.
After doing much research, I've come back to revising my macro to incorporate static variables and a MsgBox at the end to report the last 5 production numbers that have been printed.
To provide a means of bringing up this MsgBox for reference, between printing runs, I created an OnlyNum variable as string and replaced the MsgBox I had for letting the users know they were only to use numbers in this field with that message. The end of that trap diverted the flow to the bottom of the macro (where the MsgBox that displayed the last five print jobs has been placed).
So, when the status MsgBox is displayed as a result of printing it only shows the last five events. If the trap captures it, it shows the message letting the user know to only use numerals and then displays the last five events.
Code reference:
Private Sub CommandButton1_Click()
Dim Prod As String
Dim Temp As String
Dim OnlyNum As String
Static ProdNum1 As String
Static ProdNum2 As String
Static ProdNum3 As String
Static ProdNum4 As String
Static ProdNum5 As String
'Check for only numeric value of TextBox1.Text
If Not IsNumeric(TextBox1.Value) Then
OnlyNum = "only numbers allowed" & vbCrLf & vbCrLf
Cancel = True
GoTo NotToday
End If
'Remove any spaces from TextBox1.Text
Prod = Replace(TextBox1.Text, " ", "")
'If the resulting lenght is equal to 7 Print it.
If Len(Prod) = 7 Then
ActiveDocument.PrintOut
'Update recent production numbers (5 in total)
ProdNum5 = ProdNum4
ProdNum4 = ProdNum3
ProdNum3 = ProdNum2
ProdNum2 = ProdNum1
ProdNum1 = Prod & " - " & Now() ' Insert a new production number with timestamp
TextBox1.Text = "" 'Clear the value of TextBox1.Text to prepare for the next Production number
Else
MsgBox ("Production Numbers must be 7 digits and contain only numerials.")
End If
NotToday:
Application.ActivePrinter = Temp
MsgBox (OnlyNum & ProdNum1 & vbCrLf & ProdNum2 & vbCrLf & ProdNum3 & vbCrLf & ProdNum4 & vbCrLf & ProdNum5)
OnlyNum = "" 'Reset value of OnlyNum
End Sub
I built a very complex SeleniumBasic via VBA via Excel Addin setup that interacts with one of the leading ticketing system websites to scrap and populate data. The system interacts with 90+ different fields/clickables with 3 different pages, 6 different tabs, and nested popups...deployed to 120 users who use the automations about 20 times per day.
And it has been working flawlessly for over a year...
We have just provisioned 20 more users on the same system, and their automations refuse to work.
Here is where I am at with my research:
I am able to manually step through code on the new system and have it successfully go through the entire automation, so the issue probably has something to do with the speed VBA/Selenium is trying to interact with the website.
Once the system is unable to find a field or clickable, it refuses to find any other ones after that.
The way the system is built in order to go as fast as possible is via standard VBA error handling. It fails to find something, it goes to the error handler, the error handler says to wait for one second then try again. Again, this system has been working flawlessly for over a year and is currently working on 120 user's systems.
To see if maybe Selenium was refusing to reload the clickable, I broke out the error handling from a Resume to a Resume Next, and then had a do while loop with a boolean flag to keep trying until it was successful, but after the first failure, it refused to find anything else, including different fields
The one thing the 20 new users have in common is that they are all using v66 of Chrome, whereas all of the systems that are working have old copies of Chrome that are at least 9 months old
Thinking this might be an issue, I grabbed all of the ChromeDrivers and systematically went through one by one to test if we got a different performance with a different ChromeDriver, but all of the ChromeDrivers had the same error
So that is where I stand. I'm wondering if there is some key insight I am missing or a workaround that will get newer versions of Chrome to retry the fields. Or...do I need to try a VBA/Selenium tool other than SeleniumBasic to fix this. Or...do I need to roll back these 20 users to older versions of Chrome.
Thanks for sharing your expertise.
''''Check to see if there are any aliases=================================
For AliasCheck = 2 To AliasCounter + 1
If Hash = Sheets("Temp Subjects & Locations").Range("AY" & AliasCheck) Then
AliasName = Sheets("Temp Subjects & Locations").Range("AY" & AliasCheck)
AliasCount = AliasCount + 1
AliasDisplayName = Sheets("Temp Subjects & Locations").Range("AZ" & AliasCheck)
temp1 = ""
temp2 = ""
Call countryDictionary
'drops the country back into Excel to later remove the dupes
temp1 = Sheets("Temp Subjects & Locations").Range("BA" & AliasCheck)
temp2 = dict(temp1)
Sheets("Temp Subjects & Locations").Range("BG" & AliasCount + 1) = temp2
''''Click to add AKA's names
iframeText = "iframe_win_" & AddParty
robot.SwitchToDefaultContent
robot.SwitchToFrame iframeText
iframeTracker = iframeTracker + 1
iframeText = "iframe_win_" & iframeTracker
robot.SwitchToDefaultContent
robot.SwitchToFrame iframeText
robot.FindElementById("X_SUBJECT_ALTERNATE_NM.X_ALTERNATE_NM").SendKeys (AliasDisplayName)
robot.FindElementById("dijit_form_Button_0").Click
End If
Next AliasCheck
The AddParty variable is a way to track the number of the pop-up we came from.
The iFrameTracker variable is a way to track the number of the pop-up we are going to...the system sequentially numbers its pop-ups...instead of legible names...
The newer systems will make it down to the SendKeys and then decide not to work. On a resume next, it will then refuse to find the OK button ("dijit_form_Button_0")
Here is the code I was playing around with to see if I could get it to retry using a "Resume Next" instead of a "Resume"
robot.FindElementById("X_SUBJECT_ALTERNATE_NM.X_ALTERNATE_NM").SendKeys (AliasDisplayName)
Do While FailRetry = True
FailRetry = False
robot.FindElementById("X_SUBJECT_ALTERNATE_NM.X_ALTERNATE_NM").SendKeys (AliasDisplayName)
Loop
errHandler4:
If errorCounter < 21 Then
Application.wait (Now + TimeValue("00:00:01"))
errorCounter = errorCounter + 1
FailRetry = True
Resume Next
Else
MsgBox "Reached 20 second timeout. Stopping processing."
Exit Sub
End If