Share via

Excel VBA code to capture webpage

Anonymous
2012-05-10T18:26:35+00:00

I have some excel VBA code that populates a public website with name, ssn and date of birth to check selective service registration. Once the information is entered the status of registration is returned. (the data i am using in the code is for example purposes only and returns non-registraiton information). I want to capture that page (screen shot) in place in a file. I need to do this with multiple names that will be read from a spreadsheet.

The problem I have is that the code below returns a run time error of 424 and I cannot seem to resolve this error. Any suggestions to resolve this error?

Sub Test()

Dim IE As New InternetExplorer

Dim IEdoc As HTMLDocument

Dim Item As Variant

'Open IE and go to the site

IE.Visible = True

IE.navigate "https://www.sss.gov/RegVer/wfVerification.aspx"

'Wait until side it loaded

Do While IE.readyState <> READYSTATE_COMPLETE

DoEvents

Loop

'Get the body

Set IEdoc = IE.document

'Find each field and fill out

Item = IEdoc.getElementsByName("_ctl0:ContentPlaceHolder1:tbLastName")

Item.Value = "smith"

Item = IEdoc.getElementsByName("_ctl0:ContentPlaceHolder1:tbSSAN")

Item.Value = "123456789"

Item = IEdoc.getElementsByName("_ctl0:ContentPlaceHolder1:tbDOB")

Item.Value = "05121994"

IE.document.forms(0).Item("Submit1").Click

' grab the whole screen &amp;amp;amp; paste into Excel

appIE.ExecWB OLECMDID_SELECTALL, OLECMDEXECOPT_DONTPROMPTUSER

appIE.ExecWB OLECMDID_COPY, OLECMDEXECOPT_DODEFAULT

Workbooks.Add

ActiveSheet.Paste

Application.ScreenUpdating = True

appIE.Quit

End Sub

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Anonymous
    2012-05-10T23:00:56+00:00

    Is the problem that you declare IE As New InternetExplorer at the top, but then when you try to "grab the whole screen"... you start using appIE....?

    Try placing:

    Option Explicit

    at the very top of your module, then do Debug > Compile VBA Project.

    Hope that helps.

    Cheers

    Rich

    Was this answer helpful?

    0 comments No comments