I need/want to get the red bit of this macro
Sub GH() Dim i As Long With CreateObject("MSXML2.XMLHTTP") .Open "GET", "http://www.google.com", False .setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 5.1; rv:24.0) Gecko/20100101 Firefox/24.0" .send For i = 1 To Len(.responseText) Step 1023 Cells(i \ 1023 + 1, "A").Value = "'" & Mid(.responseText, i, 1023) Next End WithEnd Sub
'Into' the blue bit of this macro:
Option Explicit
Private Const INTERNET_FLAG_NO_CACHE_WRITE = &H4000000
Private Declare Function InternetOpen Lib "Wininet.dll" Alias "InternetOpenA" (ByVal lpszAgent As String, ByVal dwAccessType As Long, ByVal lpszProxyName As String, ByVal lpszProxyBypass As String, ByVal dwFlags As Long) As Long
Private Declare Function InternetReadFile Lib "Wininet.dll" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
Private Declare Function InternetOpenUrl Lib "Wininet.dll" Alias "InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal sUrl As String, ByVal sHeaders As String, ByVal lHeadersLength As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
Private Declare Function InternetCloseHandle Lib "Wininet.dll" (ByVal hInet As Long) As Integer
Public Sub GetWebPageData()
Dim hInternet, hSession, lngDataReturned As Long
Dim iReadFileResult As Integer
Dim sBuffer As String * 64
Dim sTotalData As String
Dim sUrl As String
Dim sLine As String
sUrl = "http://www.engadget.com/" 'Long Website here
hSession = InternetOpen("", 0, vbNullString, vbNullString, 0)
If hSession Then hInternet = InternetOpenUrl(hSession, sUrl, vbNullString, 0, INTERNET_FLAG_NO_CACHE_WRITE, 0)
If hInternet Then
iReadFileResult = InternetReadFile(hInternet, sBuffer, 128, lngDataReturned)
sTotalData = sBuffer
Do While lngDataReturned <> 0
iReadFileResult = InternetReadFile(hInternet, sBuffer, 128, lngDataReturned)
sTotalData = sTotalData + Mid(sBuffer, 1, lngDataReturned)
Loop
End If
iReadFileResult = InternetCloseHandle(hInternet)
'WEBPAGE loaded into sTotalData
Cells(2, 2) = sTotalData
End Sub
Both Macro's work perfectly well. But I cant get the 1st one to work on my excelvba.
They extract Source-Code from a website into Excel.
The first one does it across as many cells as it takes to get the full source code pasted into excel.
The second one does it all into 1 cell, and so has the draw back that it cant get all the data into 1 cell.
The first one, I cant use (or seem to use). No matter how many Tools>References I enable. It says Access Denied on .Send
The second one, I can use. It's a joy to see source code tangibly pasted into a cell, but due to the memory limits of cells, it obviously cant paste all the source code of the page I need.
I like the second one. Its better imo. easier to understand, more close to home in a hands-on way. I could understand it better ... and no opening of IE required! and no malarki in terms of Java Script or XML/XMLCCMS PHP malarki which I hate!!
Im so old school.
I believe you can beat the computer with old fashinoned logical down to earth thinking.
Am I strange!?!?
Anyway, I truelly believe if we can re-jig the 2nd macro to do a
For i = 1 To Len(.responseText) Step 1023 Cells(i \ 1023 + 1, "A").Value = "'" & Mid(.responseText, i, 1023)
Next
It would work the same and have the same functionality as the 1st smaller macro.
Sub GH() Dim i As Long With CreateObject("MSXML2.XMLHTTP") .Open "GET", "http://www.google.com", False .setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 5.1; rv:24.0) Gecko/20100101 Firefox/24.0" .send For i = 1 To Len(.responseText) Step 1023 Cells(i \ 1023 + 1, "A").Value = "'" & Mid(.responseText, i, 1023) Next End WithEnd Sub
'Into' the blue bit of this macro:
Option Explicit
Private Const INTERNET_FLAG_NO_CACHE_WRITE = &H4000000
Private Declare Function InternetOpen Lib "Wininet.dll" Alias "InternetOpenA" (ByVal lpszAgent As String, ByVal dwAccessType As Long, ByVal lpszProxyName As String, ByVal lpszProxyBypass As String, ByVal dwFlags As Long) As Long
Private Declare Function InternetReadFile Lib "Wininet.dll" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
Private Declare Function InternetOpenUrl Lib "Wininet.dll" Alias "InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal sUrl As String, ByVal sHeaders As String, ByVal lHeadersLength As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
Private Declare Function InternetCloseHandle Lib "Wininet.dll" (ByVal hInet As Long) As Integer
Public Sub GetWebPageData()
Dim hInternet, hSession, lngDataReturned As Long
Dim iReadFileResult As Integer
Dim sBuffer As String * 64
Dim sTotalData As String
Dim sUrl As String
Dim sLine As String
sUrl = "http://www.engadget.com/" 'Long Website here
hSession = InternetOpen("", 0, vbNullString, vbNullString, 0)
If hSession Then hInternet = InternetOpenUrl(hSession, sUrl, vbNullString, 0, INTERNET_FLAG_NO_CACHE_WRITE, 0)
If hInternet Then
iReadFileResult = InternetReadFile(hInternet, sBuffer, 128, lngDataReturned)
sTotalData = sBuffer
Do While lngDataReturned <> 0
iReadFileResult = InternetReadFile(hInternet, sBuffer, 128, lngDataReturned)
sTotalData = sTotalData + Mid(sBuffer, 1, lngDataReturned)
Loop
End If
iReadFileResult = InternetCloseHandle(hInternet)
'WEBPAGE loaded into sTotalData
Cells(2, 2) = sTotalData
End Sub
Both Macro's work perfectly well. But I cant get the 1st one to work on my excelvba.
They extract Source-Code from a website into Excel.
The first one does it across as many cells as it takes to get the full source code pasted into excel.
The second one does it all into 1 cell, and so has the draw back that it cant get all the data into 1 cell.
The first one, I cant use (or seem to use). No matter how many Tools>References I enable. It says Access Denied on .Send
The second one, I can use. It's a joy to see source code tangibly pasted into a cell, but due to the memory limits of cells, it obviously cant paste all the source code of the page I need.
I like the second one. Its better imo. easier to understand, more close to home in a hands-on way. I could understand it better ... and no opening of IE required! and no malarki in terms of Java Script or XML/XMLCCMS PHP malarki which I hate!!
Im so old school.
I believe you can beat the computer with old fashinoned logical down to earth thinking.
Am I strange!?!?
Anyway, I truelly believe if we can re-jig the 2nd macro to do a
For i = 1 To Len(.responseText) Step 1023 Cells(i \ 1023 + 1, "A").Value = "'" & Mid(.responseText, i, 1023)
Next
It would work the same and have the same functionality as the 1st smaller macro.