Macro to print selection of cells from another workbook - vba

I'd need to click one button in one Excel workbook and automatically opens another workbook from a website and prints a selection of cells from this workbook.
Until now I have the code that opens me the workbook form the website, but I would need to include the part of printing a selection of cells.
Thank you in advance!
Here is the code I have:
Sub Project4000()
'open IE, navigate to the desired page and loop until fully loaded
Set IE = CreateObject("InternetExplorer.Application")
my_url = "Link to the file in the website"
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("uid").Value = "user"
IE.Document.getElementById("password").Value = "passw"
' Click the "Search" button
IE.Document.getElementById("enter").Click
Do Until Not IE.Busy And IE.readyState = 4
DoEvents
Loop
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

Sending a value of a mergefield from to a website

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*

Crawler & Scraper using excel vba

I am trying to crawl in an intranet URL, so I can get the excel automatically select one of the options from a dropdown menu, then enter a value in a text box, then click on Find to get redirected to another page, where I want to get a value copy to another worksheet in the same workbook, I have created the below, but the code is not working, saying object required. :(
Sub Test()
Dim rng As Range
Set rng = Sheets("sheet1").Range("A1", Sheets("sheet1").Cells.Range("A1").End(xlDown))
Set ie = CreateObject("InternetExplorer.application")
ie.Visible = True
ie.Navigate ("https://gcd.ad.plc.cwintra.com/GCD_live/login/login.asp")
Do
If ie.ReadyState = 4 Then
ie.Visible = False
Exit Do
Else
DoEvents
End If
Loop
ie.Document.forms(0).all("txtUsername").Value = ""
ie.Document.forms(0).all("txtPassword").Value = ""
ie.Document.forms(0).submit
ie.Visible = True
Appliction.Wait (Now + TimeValue("00:00:02"))
DoEvents
For Each cell In rng
ie.Navigate ("https://gcd.ad.plc.cwintra.com/GCD_live/search.asp")
DoEvents
ie.Document.getElementById("cboFieldName").selectedIndex = 6
ie.Document.getElementById("txtFieldValue").Select
SendKeys (cell.Value)
DoEvents
ie.Document.getElementById("cmdFind").Click
Next cell
End Sub

Press a link on a webpage using Excel VBA

I have this code where it goes to Minecraft.net and enters the username and password, and then goes to the profile page. I need to change the password on the account, which will be in cell A1 of the worksheet. I can't seem to figure out how to click the change password link. This is my code so far:
Dim IE As Object
Sub submitFeedback3()
Application.ScreenUpdating = False
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "https://minecraft.net/login"
Application.StatusBar = "Submitting"
' Wait while IE loading...
While IE.Busy
DoEvents
Wend
' **********************************************************************
IE.Document.getElementById("username").Value = "dddddddd"
IE.Document.getElementById("password").Value = "ddd"
IE.Document.getElementById("signin").Click
'**********************************************************************
Application.StatusBar = "Form Submitted"
Set IE = Nothing
Application.ScreenUpdating = True
End Sub
If the click doesn't work then you could try to submit the html form.
' Add reference to Microsoft Internet Controls
' Add reference to Microsoft HTML Object Library
Set IE = New InternetExplorer
IE.Visible = True
IE.Navigate "https://minecraft.net/login"
While IE.Busy
DoEvents
Wend
IE.Document.getElementById("username").Value = "dddddddd"
IE.Document.getElementById("password").Value = "ddd"
Dim htmlForm As HTMLFormElement
Set htmlForm = IE.Document.getElementById("loginForm")
htmlForm.submit

Select Drop Down from Web Page with IE object

Have the below code for a drop down selection in VBA .
When I run this I get the error on the bold line saying "Runtime error 91 - Object variable or with block variable not set " ..New to VBA ....
Sub NACDP()
' open IE, navigate to the desired page and loop until fully loaded
Set ie = CreateObject("InternetExplorer.Application")
my_url = "https://cdeployna.cognizant.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
' Input the userid and password
ie.Document.getElementById("loginControl_UserName").Value = ""
ie.Document.getElementById("loginControl_Password").Value = ""
' Click the "Login" button
ie.Document.getElementById("loginControl_LoginButton").Click
Do Until Not ie.Busy And ie.readyState = 4
DoEvents
Loop
ie.Document.getElementById("ctl00_ddlRoles").selectedindex = 1
ie.Document.getElementById("ctl00_ddlRoles").FireEvent ("onchange")
Do Until Not ie.Busy And ie.readyState = 4
DoEvents
Loop
ie.Document.getElementById("ctl00_ContentBody_searchCDPList_ddlFieldName").selectedindex = 1
ie.Document.getElementById("ctl00_ContentBody_searchCDPList_ddlFieldName").FireEvent ("onchange")
ie.Document.getElementById("ctl00_ContentBody_searchCDPList_txtValue").Value = "Java"
' Click the "Search" button
ie.Document.getElementById("ctl00_ContentBody_searchCDPList_btnSearch").Click
End Sub
It seems that the "Do Until Not ie.Busy And ie.readyState = 4" loop doesn't really do what it's supposed to do. After getting the error, if you press Debug and then Continue the code, it will complete successfully. So, what is happening is that the element you're searching for still doesn't exist when the line first executes. You could patch this up with something like the following before the problem line:
Do While ie.Document.getElementById("ctl00_ContentBody_searchCDPList_ddlFieldName") Is Nothing
DoEvents
Loop
This will loop until the element is found, then the code continues successfully.