Here is what I am trying to do via Macro Automation->
-> I am trying to open the website [url]http://www.metaboanalyst.ca/MetaboAnalyst/faces/Home.jsp[/url]
-> Then clicking on the "click here to start"
-> Then checking the radio button for "Peak intensity table"
-> Then click on "Browse" the data file and select a file (File that needs to be selected) manually.
-> Then finally click on the submit button (which is not working and path to the file vanishes while clicking on the submit button and giving me an Automation error ['-2147352319 (80020101)'])
Here is the code that works fine except for the last step which is submitting->
Sub MetaboAnn()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "http://www.metaboanalyst.ca/MetaboAnalyst/faces/Home.jsp"
Do Until IE.ReadyState = 4
DoEvents
Loop
Application.Wait (Now + TimeValue("0:00:05"))
'MsgBox "Done"
IE.Visible = True
IE.Document.getElementById("form1:groupPanel1:loginLink").Click
Application.Wait (Now + TimeValue("0:00:05"))
'MsgBox "Done"
IE.Visible = True
IE.Document.getElementById("form1:tabSet1:tab1:layoutPanel7:csvButtonGroup:csvButtonGroup_2_rb").Click
Application.Wait (Now + TimeValue("0:00:03"))
'MsgBox "Done"
IE.Visible = True
IE.Document.all("form1:tabSet1:tab1:layoutPanel7:statCsvUpload_com.sun.webui.jsf.upload").Click
Application.Wait (Now + TimeValue("0:00:03"))
'MsgBox "Done"
IE.Visible = True
IE.Document.getElementById("form1:tabSet1:tab1:layoutPanel7:csvSubmitButton").Click
End Sub
If you are using IE, try to click on TOOLS, then COMPATIBILY VIEW SETTINGS and add the website you're on. It probably has something to do with older code on that website.
Related
I have been trying to create a really simple script to maintain visibility on an IE page but am currently unable to force the visibility or foreground position of an existing IE window.
I am able to successfully activate the window using WshShell.AppActivate() but it does not make the page foreground to a user. A sample from my code is below.
Basically the code loops until the user ends the notepad window. my confusion is specifically with why IE is not visible no matter what commands I send
Dim pressX
Dim FindProc
pressX = 1
' Create WScript Shell Object to access filesystem.
Set WshShell = WScript.CreateObject("WScript.Shell")
'WshShell.Run "NoScreenSaver.txt", 2, 0
' Define Which process to seek for to terminate script
strComputer = "."
FindProc = "NoScreenSaver"
Dim objApp : Set objApp = CreateObject("Shell.Application")
Dim IE : Set IE = Nothing
Dim objWindow
' Loop start
Do
' Wait for 5 minutes
WScript.Sleep 3000 '000
For Each objWindow In objApp.Windows
If (InStr(objWindow.Name, "Internet Explorer")) Then
Set IE = objWindow
Exit For
End If
Next
' check if specific notepad closed
If WshShell.AppActivate("NoScreenSaver.txt") = True Then
'WshShell.AppActivate("iexplore.exe")
'wscript.echo FindProc & " is running"
Else
wscript.echo FindProc & " is not running" & vbCrLf & "Script will now end"
pressX = 0
End If
IE.visible = True
wshshell.appactivate ie.name
IE.navigate "google.ca"
' Send dummy key
WshShell.SendKeys "{F13}"
' repeat
Loop While pressX
I never wanted to use AppActivate to check for the specific notepad window either since it would take foreground. There is some information regarding using a COM wrapper but the COM wrapper approach is not possible within my constraints.
I am using the script listed below (I honestly stole this probably from this very site) for a browse button on a form. The task is simply to start up MS File Dialog box so that a file (in this case an image file) can be selected. Once you select the record and click ok it then pastes the file name and location into a field.
Viewing the table the file name and location is pasted just as it should be. The problem comes in with a report I built. I have an image set to display with the control source linked back to that file address field. It will not display the image though.
However, if I manually type the same address character for character or even “copy”, delete, and then “paste” the same exact entry into the field the image then displays just fine on the report.
I have checked to make sure there are no spaces or characters anywhere there shouldn’t be. I am at a loss here.
Any help would be greatly appreciated and I will gladly give you my first born. Ok maybe not the first I like him but you can have the second one, she’s hell.
Private Sub Command67_Click()
On Error GoTo SubError
'Add "Microsoft Office 14.0 Object Library" in references
Const msoFileDialogFilePicker As Long = 3
'Dim FD As Office.FileDialog
Dim FDialog As Object
Dim varfile As Variant
Set FDialog = Application.FileDialog(msoFileDialogFilePicker)
EmployeePicture = ""
' Set up the File Dialog
Set FDialog = Application.FileDialog(msoFileDialogFilePicker)
With FDialog
.Title = "Choose the spreadsheet you would like to import"
.AllowMultiSelect = False
.InitialFileName = "C:\Users\" 'Folder picker needs trailing slash
.Filters.Clear
.Filters.Add "All", "*.*"
If .Show = True Then
If .SelectedItems.Count = 0 Then
'User clicked open but didn't select a file
GoTo SubExit
End If
'An option for MultiSelect = False
'varFile = .SelectedItems(1)
'EmployeePicture = varFile
'Needed when MultiSelect = True
For Each varfile In .SelectedItems
EmployeePicture = EmployeePicture & varfile & vbCrLf
Next
Else
'user cancelled dialog without choosing!
'Do you need to react?
End If
End With
SubExit:
On Error Resume Next
Set FDialog = Nothing
Exit Sub
SubError:
MsgBox "Error Number: " & Err.Number & " = " & Err.Description, vbCritical + vbOKOnly, _
"An error occurred"
GoTo SubExit
End Sub
I am using vbscript to automate an website operation using IE.
At one place, clicking a button creates a modal popup. When the popup appears, the script does not execute further and sort of freezes.
I thought of executing a second script, but I am unable to activate the popup window. The popup dialog has title as "Proceed -- Webpage Dialog", and 2 buttons - Ok and Cancel. I'm using the below code to activate the pop up window and then click Ok on it. But I am unable to capture the window. Below is the code for second script.
script2.vbs:
WScript.Sleep 5000
Msgbox "Started 2nd script"
For Each wnd In CreateObject("Shell.Application").Windows
If InStr(1, wnd.FullName, "iexplore.exe", vbTextCompare) > 0 Then
If InStr(1, wnd.Document.Title, "Proceed", vbTextCompare) > 0 Then
Set objIE = wnd
MsgBox "Found Window"
Exit For
End If
End If
Next
This does nothing, and I have no clue how to handle this popup. Any thoughts or workarounds for this, will be very helpful.
Update:
Below is the code for the main script.
script1.vbs:
Dim url
url = "http://example.com"
Set objIE = CreateObject("InternetExplorer.Application")
Set WshShell = WScript.CreateObject("WScript.Shell")
objIE.Visible = True
objIE.AddressBar = True
objIE.StatusBar = False
objIE.MenuBar = True
WshShell.AppActivate ("Internet Explorer")
objIE.Navigate url
'''
' Some code to perform website operations
'
'
WshShell.Run "script2.vbs"
''The below line triggers the popup
Set btn = objIE.Document.GetElementById("grayBtn").GetElementsByTagName("a").Item(0)
btn.Click
I am new to VBScripting. Sorry for any mistakes, or lack of necessary information. I will do my best to include everything I can to help you help me.
My problem is when I execute the script, I get the following error:
Line: 22
Char: 5
Error: Unspecified error
Code: 80004005
Source: (null)
What is strange is that I had been running the same script multiple times all day without any issue. Now when I run it, the error is displayed. Nothing in the script changed. I have tried rebooting, but that seems to have done nothing.
Here is the code:
Call Main
Function Main
Dim IE
Dim pin
Set IE = WScript.CreateObject("InternetExplorer.Application", "IE_")
Set objShellApp = CreateObject("Shell.Application")
Set IE2 = WScript.CreateObject("InternetExplorer.Application", "IE_")
pin=inputbox("Pin: ","Enter the pin to continue","")
IE.Visible = True
IE.Navigate "https://ps.hasdk12.org/admin/pw.html"
For Each objWindow in objShellApp.Windows
If LCase(objWindow.LocationName) = LCase("PowerSchool") Then
Set IE2 = objWindow
End If
WScript.Sleep (5)
Next
With IE2.Document
.getElementByID("fieldPassword").value = "username;" + pin
.getElementByID("btnEnter").click
End With
For Each objWindow in objShellApp.Windows
If LCase(objWindow.LocationName) = LCase("Start Page") Then
Set IE2 = objWindow
End If
WScript.Sleep (5)
Next
End Function
Most probably reasons why your script become faulty are variations in page loading time, or nuber of opened Shell Explorer and IE windows etc. All troubles because your script doesn't wait while IE loading page, it checks each Explorer window and just continues even if target window isn't found.
Try this code:
Call Main
Function Main()
Dim oIE
Dim sPin
Set oIE = WScript.CreateObject("InternetExplorer.Application", "IE_")
sPin = InputBox("pin: ","Enter the pin to continue", "")
oIE.Visible = True
oIE.Navigate "https://ps.hasdk12.org/admin/pw.html"
WaitIE oIE, "PowerSchool"
With oIE.Document
.getElementByID("fieldPassword").value = "username;" + sPin
.getElementByID("btnEnter").click
End With
WaitIE oIE, "PowerSchool"
End Function
Function WaitIE(oIE, sLocation)
Do Until (LCase(oIE.LocationName) = LCase(sLocation)) And (Not oIE.Busy) And (oIE.ReadyState = 4)
WScript.Sleep 5
Loop
End Function
I've removed second IE variable, why did you get IE2 via objShellApp.Windows? Maybe I miss something..? IMO you already have IE instance hence getting the same instance such way is not necessary, just control that instance you have. Also I've added separate function that waits IE to complete page loading.
Is there a way to make a msgbox show and disappear in under a second,I have been using the script below, but can only get it to close in a second.
Option Explicit
Dim Wshell, BtnCode
Set Wshell = CreateObject("wscript.shell")
BtnCode= Wshell.Popup ("test", 1, "testing")
I'm afraid this is not possible with popup.
You can do it with Internet Explorer as UI though.
Set oIE = CreateObject("InternetExplorer.Application")
With oIE
.navigate("about:blank")
.Document.Title = "Countdown" & string(100, chrb(160))
.resizable=0
.height=200
.width=100
.menubar=0
.toolbar=0
.statusBar=0
.visible=1
End With
' wait for page to load
Do while oIE.Busy
wscript.sleep 50
Loop
' prepare document body
oIE.document.body.innerHTML = "<div id=""countdown"" style=""font: 36pt sans-serif;text-align:center;""></div>"
oIE.document.all.countdown.innerText= "test message"
'the parameters is in miliseconds, so here the message is shown for half a second
wscript.sleep 500
oIE.quit