Web search using Excel VBA error and script corrections

fotodj

New Member
Joined
Jul 19, 2014
Messages
36
Office Version
  1. 2016
Platform
  1. Windows
I am trying to automate the search using VBA Excel and I recently started to get the error which I can not figure out how to fix... compile error:



11-7-2024 12-28-46 PM.jpg




Script searching this website for values from column B for example serial field value: 98-0001

VBA Code:
Sub Scramble()

 Dim cel As Range, ms As Worksheet, dom As HTMLDocument, loopRange As Range
    Const SEARCH_URL As String = "https://www.scramble.nl/index.php?option=com_mildb&view=search"

' USAF --------------------------------------------------------------------------------------------------------------------------

    Set ms = ThisWorkbook.Worksheets("Scramble")
    Set dom = New HTMLDocument
    Set loopRange = ms.Range("B2:B" & ms.Range("B" & Rows.Count).End(xlUp).Row).SpecialCells(2)

    Application.ScreenUpdating = False

    With CreateObject("winhttp.winhttprequest.5.1")

        For Each cel In loopRange

            .Open "POST", SEARCH_URL, False
            .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
            .send "Itemid=60&af=usaf&serial=" & cel & "&sbm=Search&code=&searchtype=&unit=&cn="
            dom.body.innerHTML = .responseText
            Dim recordFields As Object

            Set recordFields = dom.querySelectorAll(".rowBord td")

            If recordFields.Length > 0 Then
                With cel
                    .Offset(, -1) = recordFields.Item(2).innerText 'Type
                    .Offset(, 2) = recordFields.Item(1).innerText 'Code
                    .Offset(, 3) = recordFields.Item(4).innerText 'Unit
                    .Offset(, 10) = recordFields.Item(3).innerText 'C/N
                    .Offset(, 11) = recordFields.Item(5).innerText 'Status
                    .Offset(, 7) = "USAF"
               End With
            End If
        Next
    End With
End Sub

I'd appreciate any help on error and further testing the script...thank you
 
I'm glad to know things are working as you expect now, good luck with your project. If you have any doubts, let me know. Also, if you find my posts helpful in the future, I’d really appreciate it if you could consider liking them to support my reputation on this platform, just in case it's important some time.

Best regards,
Edgar
 
Upvote 0

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Forum statistics

Threads
1,223,631
Messages
6,173,464
Members
452,516
Latest member
archcalx

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