Sending a value of a mergefield from to a website - vba

I have a mailmerg of patient specific information that is merged into an MSword document. I need to upload it to my hospital document repository. The repository puts the document in the correct place on our server by using the patient identification number. This patient identification number is one of the fields within the mail merge document. I am trying to send the patient id to the webpage without manually typing the ID into the web page. Can anyone help? I have tried to use VBA but I can't quite get the code correct
*Sub Macro1()
'
' Macro1 Macro
'
'Sub IE Automated
Dim ie As InternetExplorer
Dim sURL As String
sURL = "http://cedupload.southend.nhs.uk/"
Set ie = New InternetExplorer
With ie
.Top = 0
.Left = 0
.Width = 1000
.Height = 750
.AddressBar = False
.StatusBar = False
.ToolBar = 0
.Visible = True
.Navigate sURL
Do Until Not .Busy And .ReadyState = 4
DoEvents
Loop
.Document.all("PatientIdentifier") = ThisDocument.MailMerge.Fields.Item.Copy(Unit_No_)
Application.wait Now + TimeSerial(0, 0, 5)
End With
Do Until Not ie.Busy
DoEvents
Loop
ie.Document.all("btn btn-default").Click
Set ie = Nothing
Err.Clear
End Sub*

Related

Getting 438 error while entering data on textbox on IE. This text box is on another TAB

I am doing some automation on IE browser. On this i am logging into the web application and after logging when i am clicking on botton the web opens a new tab where i need to enter the data onto the textbox but here i am getting an error 438. below is my code. please help me out. i highlighted the line in bold where i am getting an error. The last one i am clicking on end tab and i am getting an error on that
Sub upload()
Dim myValue As Variant
Dim IETab1Number As Integer
Dim IETab2Number As Integer
Dim IETab3Number As Integer
' open IE, navigate to the desired page and loop until fully loaded
Set IE = CreateObject("InternetExplorer.Application")
my_url = "http://englogin.sbc.com/ELP/"
With IE
.Visible = True
.Navigate my_url
.Top = 50
.Left = 530
.Height = 400
.Width = 400
Do Until Not IE.Busy And IE.readyState = 4
DoEvents
Loop
End With
' Input the userid and password
IE.document.getElementById("GloATTUID").Value = "Zf9775"
IE.document.getElementById("GloPassword").Value = "MrsCooper$99"
' Click the "Login" button
IE.document.getElementById("GloPasswordSubmit").Click
Do Until Not IE.Busy And IE.readyState = 4
DoEvents
Loop
' Click the "Continue" button
IE.document.getElementById("successButtonId").Click
Do Until Not IE.Busy And IE.readyState = 4
DoEvents
Loop
' Click the "MIC" button
IE.document.getElementById("btnMechanizedInventoryCreation").Click
Do Until Not IE.Busy And IE.readyState = 4
DoEvents
Loop
Set html = IE.document
html.querySelector("a[href='#MIC']").Click
IE.document.querySelector("[name=telco11iProjectNumber]").Value = "123456"
' Enter JOB Number" button
'myValue = InputBox("Give me some input")
End Sub

Excel VBA code to fetch value/maltiple value from web site

I am trying to fetch data from http://www.dsebd.org/displayCompany.php?name=LINDEBD by using VBA code in excell.
trying to get the follwing data from this links
Total No. of Outstanding Securities
Sector
Company Name
am trying with,
Sub GetData()
Set IE = CreateObject("InternetExplorer.Application")
my_url = "http://www.dsebd.org/displayCompany.php?name=LINDEBD"
With IE
.Visible = True
.navigate my_url
.Top = 50
.Left = 530
.Height = 400
.Width = 400
Do Until Not IE.Busy And IE.readyState = 4
DoEvents
Loop
End With
Application.Wait (Now() + TimeValue("00:00:016")) ' For internal page refresh or loading
Set Results = IE.document.getElementsByTagName("table")
For Each itm In Results
If itm.classname = "lgn" Then
dd = itm.getAttribute("href")
Exit For
End If
Next
' if you wnat to click the link
itm.Click
' otherwise
'Range("a1").Value = dd
MsgBox dd
End Sub
Is it possible to collect data from this site
First, you have to iterate the table(table), then you iterate the rows(tr), then within that you iterate the cells(td). These are not links on this page.
Note: The following will get you the value you seek, but this code will be subject to constant change if the website changes.
Sub GetData()
Set IE = CreateObject("InternetExplorer.Application")
my_url = "http://www.dsebd.org/displayCompany.php?name=LINDEBD"
With IE
.Visible = True
.navigate my_url
.Top = 50
.Left = 530
.Height = 400
.Width = 400
Do Until Not IE.Busy And IE.readyState = 4
DoEvents
Loop
End With
Application.Wait (Now() + TimeValue("00:00:016")) ' For internal page refresh or loading
Set Results = IE.document.getElementsByTagName("table")
For Each itm In Results
Set rowAlt = IE.document.getElementsByClassName("alt")
For Each itmTR In rowAlt
Set tdValues = itmTR.getElementsByTagName("td")
If tdValues.Item(0).innerText = "Total No. of Outstanding Securities" Then
MsgBox tdValues.Item(1).innerText 'the value you seek
Exit Sub 'don't continue this loop
End If
Next
Next
End Sub

vba scrape non-static web table data

I'm trying to create a macro that scrape and import tables from a web page,
More specifically, I want to get two tablestables pointed by arrows, please ignore the text in the table if it doesn't make sense, I translated using google. These tables are updated automatically so I used IE approach(by #ron), didn't scrape any data. I'm exhausted, can anyone please help me? I'm a vba newbie, appreciate any help.
Sub test()
' open IE, navigate to the website of interest and loop until fully loaded
Set IE = CreateObject("InternetExplorer.Application")
my_url = "http://www.neeq.com.cn/static/statisticdata.html"
With IE
.Visible = False
.navigate my_url
.Top = 50
.Left = 530
.Height = 400
.Width = 400
Do Until Not IE.busy And IE.ReadyState = 4
DoEvents
Loop
End With
Set tbl = IE.Document.getElementsByTagName("table")
For Each itm In tbl
i = 1
For Each itm2 In itm.Rows
For Each cell In itm2.Cells
ActiveSheet.Cells(i, 2) = cell.innerText
i = i + 1
Next
Next
Next
end sub()
You must select "tr" from your table object For Each Rows
As you use IE, non statix should be return (javascript is executed)
i = 1
For Each itm2 In tbl.getElementsByTagName("tr")
test with debug.print
you select html then tables -> tr -> td
Sub test()
' open IE, navigate to the website of interest and loop until fully loaded
Set IE = CreateObject("InternetExplorer.Application")
my_url = "http://www.neeq.com.cn/static/statisticdata.html"
With IE
.Visible = False
.navigate my_url
.Top = 50
.Left = 530
.Height = 400
.Width = 400
Do Until Not IE.busy And IE.ReadyState = 4
DoEvents
Loop
End With
Set tbl = IE.Document.getElementsByTagName("table")
For Each itm In tbl
i = 1
For Each itm2 In itm.getElementsByTagName("tr")
For Each cell In itm2.getElementsByTagName("td")
ActiveSheet.Cells(i, 2) = cell.innerText
i = i + 1
Next
Next
Next
end sub

VBA Binding modification

I have tried to modify on this sample code given to me by ron
Sub test()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
my_url = "http://www.google.com"
With IE
.Visible = True
.navigate my_url
.Top = 50
.Left = 530
.Height = 400
.Width = 400
Do Until Not IE.Busy And IE.readyState = 4
DoEvents
Loop
End With
' Find the desired url and click
Set Results = IE.document.getElementsByTagName("a")
For Each itm In Results
If itm.outerhtml = "B.A.C. VII" Then
itm.Click
Do Until Not IE.Busy And IE.readyState = 4
DoEvents
Loop
Exit For
End If
Next
End Sub
Now i am not a fan of late binding so i am trying to modify the first two statements from
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
and replace them with
Dim IE As InternetExplorer.Application
Set IE = New InternetExplorer.Application
However this doesn't work on my code even if i have the Microsoft Internet Controls and the the Microsoft HTML Object Library activated on references as you can see in the picture below.
WHY THAT?
Dear mehow
I have thought of that but it gives me error just look
Dim ie As InternetExplorer
Set ie = new InternetExplorer
as InternetExplorer is the class name

Scraping dynamic web page with VBA based on XMLHTTP object

I have problem with scraping table data from this page [http://www.eex.com/en/market-data/power/derivatives-market/phelix-futures]. I use this code, but do not scrape any data:
Public Sub ScrapTableData()
Dim sURL As String
Dim XMLHttpRequest As XMLHTTP
Dim HTMLDoc As New HTMLDocument
Dim elc As HTMLHtmlElement
Dim i As Integer
sURL = "http://www.eex.com/en/market-data/power/derivatives-market/phelix-futures"
Set XMLHttpRequest = New MSXML2.XMLHTTP
XMLHttpRequest.Open "GET", sURL, False
XMLHttpRequest.responseXML.async = False
XMLHttpRequest.send
Do While XMLHttpRequest.Status <> 200
DoEvents
Loop
While XMLHttpRequest.ReadyState <> 4
DoEvents
Wend
HTMLDoc.body.innerHTML = XMLHttpRequest.responseText
' Tables
Dim tbl As HTMLTable, row As HTMLTableRow, cell As HTMLTableCell
i = 1
For Each tbl In HTMLDoc.getElementsByTagName("table")
For Each row In tbl.Rows
For Each cell In row.Cells
ActiveSheet.Cells(i, 5) = cell.innerText
i = i + 1
Next
Next
Next
End Sub
My code does not find HTML table tags.
Also, if I use this part of code, do not list all HTML tags (for example HTML DIV tag) and HTML that describes 6 buttons:
i = 0
Dim elc As HTMLHtmlElement
For Each elc In HTMLDoc.all
Worksheets("Tables").Range("A1").Offset(i, 0) = elc.tagName
i = i + 1
Next
6 buttons: Year, Quarter, Month,..., Day
I need to simulate click on them to display (scrape) different tables' data.
I don't think the XMLHTTP approach will work in this case, you need to open IE. The following code will do this. You may need to modify the loop to put data in your worksheet, I didn't tinker with this. At the end, I've also placed some code that will change the tabs. Hope this helps
Sub test()
' open IE, navigate to the website of interest and loop until fully loaded
Set IE = CreateObject("InternetExplorer.Application")
my_url = "http://www.eex.com/en/market-data/power/derivatives-market/phelix-futures"
With IE
.Visible = True
.navigate my_url
.Top = 50
.Left = 530
.Height = 400
.Width = 400
Do Until Not IE.Busy And IE.readyState = 4
DoEvents
Loop
End With
' Collect data from tables
Set tbl = IE.document.getElementsByTagName("table")
For Each itm In tbl
i = 1
For Each itm2 In itm.Rows
For Each cell In itm2.Cells
ActiveSheet.Cells(i, 5) = cell.innertext
i = i + 1
Next
Next
Next
' Click on the 6 buttons, substitute "week", "year", etc. for the button you want to click
Set Results = IE.document.getElementsByTagName("a")
For Each itm In Results
If InStr(1, itm.innertext, "month", vbTextCompare) > 0 Then
itm.Click
Do Until Not IE.Busy And IE.readyState = 4
DoEvents
Loop
Exit For
End If
Next
' Do whatever is next
End Sub