I am trying to automate a process of downloading file from a website. At the moment I am able to open a link that runs a javascript which produces an output file, here's my code:
Sub WebDataExtraction()
Dim URL As String
Dim IeApp As Object
URL = "http://si3.bcentral.cl/Siete/secure/cuadros/DescargarExcel.aspx?DropDownListFrequency=&DrDwnCalculo=NONE&codCuadro=UF_IVP_DIARIO"
Set IeApp = CreateObject("InternetExplorer.Application")
IeApp.Navigate URL
End Sub
When I run the sub the IE View Downloads window pops out. To download the file I am trying to follow this approach, however while I am using the attached code I am unable to find a child window.
Can somebody advise me how to proceed from here? Or maybe any suggestion how to approach this problem differently?
Related
I am just starting to learn Internet Explorer Automation using VBA and I am facing an issue.
The Document object is empty which prevents me from going further than just loading a page. I have been looking around the net for a solution to this and could not find anything working so here I am, asking for your help.
NB: My VBA level is intermediate
Windows 8.1 pro 64 bit
I wrote an example code
I had a the same issue (nothing in the .document) , with Internet Explorer 11.
I had to add the site to the Compatibility View list (gear, compatibility view, add)
Hopefully this will help someone avoid the time I spent looking for a solution.
This code works for me. It uses a loop to wait until navigation is complete.
Sub NavigateGoogle()
Dim i As Long
Dim ie As InternetExplorer
Dim Googledoc As HTMLDocument
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.navigate "www.google.com"
Do
DoEvents
Loop While ie.Busy
Set Googledoc = ie.document
Debug.Print Googledoc.all(0).innerHTML
Set ie = Nothing
End Sub
I am currently using Office 2010, Visual Basic for Applications 7, and Internet Explorer 9.
The current issue I've been having is that using an IE object seems to fail on our intranet, and I was wondering if there was a fix for this.
Functioning code:
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate "http://www.google.com"
WaitUntilReady IE
'Application.Wait (Now + TimeValue("00:00:10"))
'IE.Visible = True
MsgBox (IE.Document.body.innerHTML)
Broken code:
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate "http://intranet/"
WaitUntilReady IE
'Application.Wait (Now + TimeValue("00:00:10"))
'IE.Visible = True
MsgBox (IE.Document.body.innerHTML)
Functioning code does exactly what it should. Makes an IE object which doesn't show up visibly on screen, and returns a message box with the HTML code contents of google.com
Broken code loads our intranet home page, in a VISIBLE IE window, and returns this error:
Run-time error '-2147417848 (80010108)'
Automation error
The object invoked has disconnected from its clients
I've read through Excel VBA Controlling IE local intranet which suggested using an IP address instead of intranet/ which doesn't work because the IP directs to a different splash screen.
I've also tried using
Set IE = New InternetExplorerMedium
But this A- didn't seem to work either, and B- would mean making sure all my fellow employees enable this Reference.
Also, I've tried loading google.com first, then having it navigate to intranet/, which also didn't help.
Anyone have any suggestions? From my understanding, loading intranet/ is causing IE to disconnect from Excel somehow?
SO! After several days of research and at a complete loss for what was going on, I stumbled on to someone talking about intranet compatibility mode in another article.
Force "Internet Explorer 8" browser mode in intranet
Things happened to click in my head when I read this, realizing that if IE loaded in compatibility, it would explain why the Excel VBA macro lost control of IE, as compatibility mode might be loading as a separate instance of IE.
Settings > Internet Options > Security > Local Intranet > Sites >
Disable "Auto detect intranet" and enable "Include all network paths (UNCs)" fixes the error I was having, perfectly.
'simply replace -seem to work
' Set ie = CreateObject("InternetExplorer.Application")
Set ie = New InternetExplorerMedium
another solution
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate ("http://URLOnMyIntranet/site.html")
IE.Visible = True
Set IE = nothing
Set objShellApp = CreateObject("Shell.Application")
For Each objWindow In objShellApp.Windows
Debug.Print objWindow.LocationName
If LCase(objWindow.LocationName) = LCase("Your windows name, use debug to find out") Then
Set IE = objWindow
End If
Next`enter code here`
also see this post
I'm successfully opening pages with
Dim o As Object
o = CreateObject("InternetExplorer.Application")
o.navigate2("http://www.google.com")
Is it possible to navigate webpage without loading images ?
1) This is VBS or VB6, not VB.Net.
2) You are essentially starting IE, it's up to the user to go to their options and
let IE load up images or not.
What are you trying to do?
I am trying to pull elevation data from a website
http://www.gpsvisualizer.com/convert_input
I have successfully figured out how to programmatically click the 'Choose File' Button that brings up an Open File Dialog Box.
Private Sub browser_DocumentCompleted() Handles browser.DocumentCompleted
hDoc = browser.Document
Dim hInp As HtmlElement = hDoc.GetElementById("uploaded_file_1")
If hInp IsNot Nothing Then
hInp.Focus()
hInp.InvokeMember("Click")
End If
End Sub
Now I am stuck as to how to interact with the pop-up box. I need to fill in the file name of the file that I need to convert and click open from this Dialog box. Does anyone know how to do this?
Thanks!
Currently I am adding the path to the files that I want to upload to a listbox then copying each one to the clipboard and using sendkeys. I am not to thrilled with this method but it works.
I have a VB.Net app that needs to print a bunch of pages from a secure intranet site; the app was made and was working for a non-secure site but now the app needs to login before accessing the web pages necessary to print.
I get the error "Object Reference not set to an instance of an object" when I use my new Sub which follows:
Private Sub SiteLogin()
WebBrowser1.Navigate("http://url/login/")
WebBrowser1.Document.GetElementById("user").SetAttribute("value", "username")
WebBrowser1.Document.GetElementById("password").SetAttribute("value", "mypassword")
WebBrowser1.Document.GetElementById("submit").InvokeMember("click")
End Sub
I got the code from this VB tutorial, but I seem to be missing something in how I'm referencing the WebBrowser.Document object. I've never used VB.Net before so I don't know much about this problem, I have the following sub which DOES work from the original program however:
Private Sub WebPrint()
WebBrowser1.Navigate(strUrl)
WebDocLoaded = False
'lblMessage.Text = "Waiting for report page to load"
Do Until WebDocLoaded
System.Windows.Forms.Application.DoEvents()
Loop
End Sub
This Sub prints the given page in IE, so I figured I could use the same WebBrowser1 object for the login Sub, as I don't know how to or whether I should declare a separate object for the SiteLogin Sub. Both of these functions are called after the WebBrowser1 object is defined however.
I just need to be able to submit a simple login form to a set URL, and this info needs to all be hardcoded (there's no option to set the location or login info nor should there be). If there's another way to log into this site via VB.Net or if I need to give more information let me know.
.Navigate returns before the page load is complete so the DOM is not ready & .Document is not accessible.
See; How to wait until WebBrowser is completely loaded in VB.NET?