PDA

View Full Version : Complex VBA - Trying to use specific online calculator and download data to excel



HasenCH
04-07-2018, 08:52 AM
Hello,


I am new to Excel VBA and would appreciate if someone can help me to find the solution to the problem. I have an excel sheet with some specific values, and I would like excel to open the website, select the appropriate calculator and enter the values and save the output to excel.


With various online tutorials, I am able to achieve the following


1: Open the website 2: Select the appropriate calculator


But after that, I am not able to get my code to work. I have spent few hours looking for an online solution but no help. I would appreciate if someone can help me.


Please teach me how can I get my code to do the following


1: Do the calculation for all the values in my excel sheet 2: Copy the total amount to the excel sheet.


I have attached my excel file and the code.


Excel File Link: https://www.dropbox.com/s/96mz24a9sho4b2l/MACROEABLED.xlsm?dl=0


Thank you.






Sub automaticformfilling()


Dim ie As Object


Set ie = CreateObject("internetexplorer.application")


With ie
.Visible = True
.navigate "https://cf.oeb.ca/html/_calculator/BillCalc.cfm"
'Wait for loading
Do While .busy
DoEvents
Loop


Do While .readystate <> 4
DoEvents
Loop


End With


Set district = ie.document.getelementbyid("ddCompanies")


For i = 1 To district.Options.Length
If district.Options(i).Text = "ENWIN Utilities Ltd." Then
district.selectedindex = i
Exit For
End If

Next i


ie.document.getelementbyid("ddCompanies").fireevent ("onchange")


Set variableusage = ie.document.getelementbyid("txtEnterUsage")
SendKeys ("{BACKSPACE}")


End Sub