Firstly may I apologise for the fact that I am not the best with computers,
I have quite a large excel sheet for which I have to copy and paste 10 columns per row into an online form.
Is it possible to create a macro for this and if yes how can I do so.
Also please keep in mind that I am at work, so I'm limited from the use of plugins and I unfortunately have to use internet explorer.
Your help would be much adored,
Thank You
Yes it is possible. You can use IE to automate this using vba.
Sub xtremeExcel()
Dim HTMLDoc As HTMLDocument
Dim oBrowser As InternetExplorer
sURL = "*******Paste URL Here************"
Set oBrowser = New InternetExplorer
oBrowser.Silent = True
oBrowser.navigate sURL
oBrowser.Visible = True
Do
Loop Until oBrowser.readyState = READYSTATE_COMPLETE
Set HTMLDoc = oBrowser.document
'Use firebug to identify the textbox or object you need. and you can set its value like
'HTMLDoc.GetElementByID("abcd").value="xyz"
End Sub
Related
I am sorry if this is a very basic question, but I'm really desperate. I want to fetch the output of the website https://cactus.nci.nih.gov/chemical/structure/78-70-6/smiles, and input it into an Excel cell using VBA. Does anyone know of a simple and straightforward way of doing this?
In a way, I would like something like "curl", in bash, but that could be used in VBA for Excel.
I'm using Excel for Mac, Version 16.16.14, with VBA 7.1.
I've tried many of the approaches suggested online, and nothing seemed to work on my version of Excel.
Thanks a lot.
This should do the trick;
Dim InternetExplorer As Object 'dim your internet explorer
Dim WebsiteURL As String: WebsiteURL = "https://cactus.nci.nih.gov/chemical/structure/78-70-6/smiles" 'dim and set your website url
Dim WebsiteText As String 'dim a variable to store the website text
Set InternetExplorer = CreateObject("InternetExplorer.Application") 'set your internet explorer
With InternetExplorer
.Visible = 1 'set to show (if you put 0 the browser would be hidden - just remember to set to nothing at end)
.navigate WebsiteURL 'navigates to websiteurl
While .Busy Or .readyState <> 4 'waits for page to load
DoEvents
Wend
End With
Dim WebPage As HTMLDocument 'dim your webpage as htmldocument
Set WebPage = InternetExplorer.document 'set your webpage to the internet explorer
WebsiteText = WebPage.body.innerText: Range("A1").Value = WebsiteText 'puts website text into variable : write to whatever cell you want
EDIT:
Just noticed you said for MAC - My bad as this uses internet explorer
I have a webpage with some text in a HTML Span like so:
<span id="ctl00_ContentPlaceHolder1_FormView1_GridView1_ctl02_lb_ExpiryDate">Expiry Date : 16/02/2018</span>
I am trying to get this value display it as a message in excel using the below code:
Sub PullExpiry()
Dim appIE As Object
Set appIE = CreateObject("internetexplorer.application")
With appIE
.Navigate "https://www.brcdirectory.com/InternalSite//Site.aspx?BrcSiteCode=" & Range("J6").Value
.Visible = True
End With
Do While appIE.Busy Or appIE.ReadyState <> 4
DoEvents
Loop
Set getPrice = appIE.Document.getElementById("ctl00_ContentPlaceHolder1_FormView1_GridView1_ctl02_lb_ExpiryDate")
Dim myValue As String
myValue = getPrice.innerText
appIE.Quit
Set appIE = Nothing
MsgBox myValue
End Sub
This was working on my laptop (operating windows) but it does not work on my computer (also operating windows). Both windows are the same version with the same version of IE. I cannot explain it.
I have Microsoft Office and Excel Object libraries turned on in both references.
I get an error about an active x component not being able to create something
Please can someone show me where i am going wrong?
You need to add Microsoft Internet Controls to your references to be able to create the object. You may have to register the shdocvw.dll library on your computer. It may be registered on your laptop already which is why it might be bombing on your computer.
How to register a .dll
MSDN Documentation: look at the last sentence before the C# example.
Similar Question
After playing around a little bit and ensuring everything was registered, this ran fine on my PC:
Public Sub ie()
Dim ieApp As SHDocVw.InternetExplorerMedium
Dim html As HTMLDocument
Set ieApp = New SHDocVw.InternetExplorerMedium
ieApp.Visible = True
ieApp.Navigate "http://internalAddress/"
Do While ieApp.Busy Or ieApp.ReadyState <> 4
DoEvents
Loop
Set html = ieApp.Document.getElementById("myID")
End Sub
I'm new to using VBA. I'm trying to wrap my head around using it correctly. I have this code and it seems to work perfectly the 1st time around but then I can't get it to work again. I'm trying to get to the match summary page for basketball games played. If I could get some assistance it would be much appreciated
Sub Test()
Dim URL As String
Dim IE As InternetExplorer
Dim HTMLdoc As HTMLDocument
Dim TDelements As IHTMLElementCollection
Dim TDelement As HTMLTableCell
Dim i As Integer
URL = "http://www.flashscore.com/basketball/"
Set IE = New InternetExplorer
With IE
.Navigate URL
.Visible = True
While .Busy Or .ReadyState <> READYSTATE_COMPLETE: DoEvents: Wend
Set HTMLdoc = .Document
End With
Set TDelements = HTMLdoc.getElementsByTagName("td")
For Each TDelement In TDelements
If TDelement.Title = "Click for match detail!" Then
TDelement.Click
End If
Next
End Sub
try using this
Dim IE as Object
Set IE = CreateObject("InternetExplorer.Application")
--corrected
Your code actually looks fine with one small tweak- make sure to add:
IE.Quit
Set IE = Nothing
End Sub
Otherwise multiple IE instances would be hiding in the background- others have suggested using CreateObject("InternetExplorer.Application") but I much prefer using the methodology you used so you have a true InternetExplorer object that you can see its methods & properties if necessary..
I ran it and didn't get an errors, but also didn't get any TDs to meet the If clause- this could just be due to the timing of the website and its data, element.title is not an attribute I have seen used very often so perhaps this is the source of your issues and you should revisit what attribute you are checking to meet your if clause.
Hope this helps,
ThesilkCode
I am trying to make a currency calculater in VBA excel, and I cannot make it work. My code below show how far I am. My problem is that I cannot get the calculated number on the web page into excel (the sDD). This code only concerns from DKK to USD, which I will change later, but right now the problem is to get the exchange amount into Excel. Hope you can help!
code:
Sub currency_1()
Dim Price As Double
Dim IE As New InternetExplorer
Price = Range("C4")
IE.Visible = True
IE.Navigate "https://finance.yahoo.com/currency-converter/#from=DKK;to=USD;amt=" & Price
Do
DoEvents
Loop Until IE.ReadyState = READYSTATE_COMPLETE
Dim Doc As HTMLDocument
Set Doc = IE.Document
On Error Resume Next
Dim sDD As Double
sDD = Doc.getElementById("yui_3_18_1_1_1467628123397_410").Value
IE.Quit
Range("E4").Value = sDD
End Sub
Alright, I'm pretty sure your problem is I cannot find the "yui_3_18_1_1_1467628123397_410" on the source code for that website.
Your On error resume next is really bad coding and will hide this issue. Remove it, run it again and see if it bugs out
I'm trying to write a macro that will open a given URL and perform a File >> SaveAs... The URL returns an XML output on the screen and I want to save it. Then I can have Excel open the file and work on it (this part I can do).
Here's basically what I want to do and it works except for the SaveAs bit:
Sub Main()
REM Reference to "Microsoft Internet Controls" is being used.
Dim objIE As InternetExplorer
Set objIE = New InternetExplorer
With objIE
.Visible = True
.navigate "http://exampleURL.comany.com/ServerOutput/XmlFile.xml"
Do Until .readyState = 4
DoEvents
Loop
REM The next line fails
.SaveAs "C:\temp\test.xml"
.Application.Quit
End With
Set objIE = Nothing
End Sub
A plain "Save" is fine if that's all that will work. Just looking for a way to save the output on the screen. Thanks!
Maybe something like this can help?
Public Sub GetXML()
Dim oXML As New MSXML2.XMLHTTP60
Dim xURL As String
'Retrieve XML.
xURL = "http://exampleURL.comany.com/ServerOutput/XmlFile.xml"
oXML.Open "GET", xURL, False
oXML.send
'Put into sheet.
ThisWorkbook.Sheets("Sheet1").Range("A1").Value = oXML.responseXML.XML
End Sub
EDIT: Make sure the reference to Microsoft XML, v3.0 is enabled for this.