Storing an entire webpage in a string

exclusiveicon

New Member
Joined
Feb 9, 2015
Messages
2
Can someone please advise me on how to accomplish this. I found some code that seems to be doing the job but when it stores the web source code it only stores about a quarter of the web source code.

how can I grab all the source code? The source code is about 301,000 characters (spaces included)

Code:
Function GetPageSource(ByVal URL As String) As Variant    
    Dim msg As String
    
      ' Reset the Global variables.
        PageSrc = ""
        Set HTMLdoc = Nothing
        
        With CreateObject("MSXML2.XMLHTTP")
            .Open "GET", URL, True
            .Send
                                
            While .readyState <> 4: DoEvents: Wend
                            
          ' Check for any server errors.
            If .statusText <> "OK" Then
              ' Check for WinHTTP error.
                msg = GetWinHttpErrorMsg(.Status)
                If msg = "" Then msg = .statusText
                
              ' Return the error number and message.
                GetPageSource = "ERROR: " & .Status & " - " & msg
                Exit Function
            End If
                            
          ' Save the HTML code in the Global variable.
            PageSrc = .responseText
        End With


      ' Create an empty HTML Document.
        Set HTMLdoc = CreateObject("htmlfile")
        HTMLdoc.Open URL:="text/html", Replace:=False
            
      ' Convert the HTML code into an HTML Document Object.
        HTMLdoc.write PageSrc


      ' Terminate Input-Output with the Global variable.
        HTMLdoc.Close
        
      ' Return the HTML text of the web page.
        GetPageSource = PageSrc
        
End Function
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Forum statistics

Threads
1,216,588
Messages
6,131,587
Members
449,657
Latest member
Timber5

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