VBA Grabbing from Web

CORECAGE

New Member
Joined
Oct 31, 2016
Messages
1
Hi everybody,

I am relatively new to knowing anything VBA related. I am hoping one of you could help answer a question I have partaking in a bit of code I got and made changes to.

What I am trying to do is grab a bit of information from a website "Acer" to compare certain things. I can run the code and successfully open the website I am looking for, but it ends there. I cant seem to input my columns I have listed into the search bar and successfully .click the search button.

I get this error "Run-time error '91': Object variable or With block variable not set" at What.Item(0).Value = partnumber
Also sorry, couldn't figure out how to put it in its own box.




Sub Test()


Dim eRow As Long
Dim ele As Object


Set sht = Sheets("Sheet1")
RowCount = 1
sht.Range("A" & RowCount) = "1"
sht.Range("B" & RowCount) = "2"
sht.Range("C" & RowCount) = "3"
sht.Range("D" & RowCount) = "4"
sht.Range("E" & RowCount) = "5"
sht.Range("F" & RowCount) = "6"
sht.Range("G" & RowCount) = "7"
sht.Range("H" & RowCount) = "8"
sht.Range("I" & RowCount) = "9"
sht.Range("J" & RowCount) = "10"
sht.Range("K" & RowCount) = "11"
sht.Range("L" & RowCount) = "12"
sht.Range("M" & RowCount) = "13"
sht.Range("N" & RowCount) = "14"
sht.Range("O" & RowCount) = "15"
sht.Range("P" & RowCount) = "16"
sht.Range("Q" & RowCount) = "17"
sht.Range("R" & RowCount) = "18"
sht.Range("S" & RowCount) = "19"
sht.Range("T" & RowCount) = "20"
sht.Range("U" & RowCount) = "21"
sht.Range("V" & RowCount) = "22"
sht.Range("W" & RowCount) = "23"
sht.Range("X" & RowCount) = "24"
sht.Range("Y" & RowCount) = "25"
sht.Range("Z" & RowCount) = "26"
sht.Range("AA" & RowCount) = "27
sht.Range("AB" & RowCount) = "28"
sht.Range("AC" & RowCount) = "29"
sht.Range("AD" & RowCount) = "30"
sht.Range("AE" & RowCount) = "31"
sht.Range("AF" & RowCount) = "32"


eRow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row


Set objIE = CreateObject("InternetExplorer.Application")


'For x = 2 To 2


'PartNumber = Cells(2, x)
'partnumber = Cells(4, 4)
partnumber = InputBox("PartNumber")


With objIE
.Visible = True
.navigate "http://www.acer.com/ac/en/US/search"


Do While .Busy Or _
.readyState <> 4
DoEvents
Loop


Set What = .document.getElementsByName("No")
What.Item(0).Value = partnumber
.document.getElementByName("Search").Click


Do While .Busy Or _
.readyState <> 4
DoEvents
Loop


For Each ele In .document.all


Select Case ele.classname
Case "result"
RowCount = RowCount + 1
Case "0"
sht.Range("A" & RowCount) = ele.innertext
Case "1"
sht.Range("B" & RowCount) = ele.innertext
Case "2"
sht.Range("C" & RowCount) = ele.innertext
Case "3"
sht.Range("D" & RowCount) = ele.innertext
Case "4"
sht.Range("E" & RowCount) = ele.innertext
Case "5"
sht.Range("F" & RowCount) = ele.innertext
Case "6"
sht.Range("G" & RowCount) = ele.innertext
Case "7"
sht.Range("H" & RowCount) = ele.innertext
Case "8"
sht.Range("I" & RowCount) = ele.innertext
Case "9"
sht.Range("J" & RowCount) = ele.innertext
Case "10"
sht.Range("K" & RowCount) = ele.innertext
Case "11"
sht.Range("L" & RowCount) = ele.innertext
Case "12"
sht.Range("M" & RowCount) = ele.innertext
Case "13"
sht.Range("N" & RowCount) = ele.innertext
Case "14"
sht.Range("O" & RowCount) = ele.innertext
Case "15"
sht.Range("P" & RowCount) = ele.innertext
Case "16"
sht.Range("Q" & RowCount) = ele.innertext
Case "17"
sht.Range("R" & RowCount) = ele.innertext
Case "18"
sht.Range("S" & RowCount) = ele.innertext
Case "19"
sht.Range("T" & RowCount) = ele.innertext
Case "20"
sht.Range("U" & RowCount) = ele.innertext
Case "21"
sht.Range("V" & RowCount) = ele.innertext
Case "22"
sht.Range("W" & RowCount) = ele.innertext
Case "23"
sht.Range("X" & RowCount) = ele.innertext
Case "24"
sht.Range("Y" & RowCount) = ele.innertext
Case "25"
sht.Range("Z" & RowCount) = ele.innertext
Case "26"
sht.Range("AA" & RowCount) = ele.innertext
Case "27"
sht.Range("AB" & RowCount) = ele.innertext
Case "28"
sht.Range("AC" & RowCount) = ele.innertext
Case "29"
sht.Range("AD" & RowCount) = ele.innertext
Case "30"
sht.Range("AE" & RowCount) = ele.innertext
Case "31"
sht.Range("AF" & RowCount) = ele.innertext


End Select
'Next ele


Next ele


End With


'Macro1


'End If


Set objIE = Nothing




End Sub
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
I would have thought to start from the Data Ribbon\From Web to get the data. Builds a query that will refresh just as easy (or easier). The easy present wrench in either plan is when the webpage gets redesigned, and I bet updating the query will be easier than the VBA.
 
Upvote 0

Forum statistics

Threads
1,216,098
Messages
6,128,812
Members
449,468
Latest member
AGreen17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top