Option Explicit
Const scUserAgent = "IE 6.0"
Const INTERNET_OPEN_TYPE_DIRECT = 1
Const INTERNET_OPEN_TYPE_PROXY = 3
Const INTERNET_FLAG_RELOAD = &H80000000
Private Declare Function InternetOpen Lib "wininet" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Private Declare Function InternetCloseHandle Lib "wininet" (ByVal hInet As Long) As Integer
Private Declare Function InternetReadFile Lib "wininet" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
Private Declare Function InternetOpenUrl Lib "wininet" Alias "InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal lpszUrl As String, ByVal lpszHeaders As String, ByVal dwHeadersLength As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Long
Function GetFileLength(sUrl As String)
Dim hOpen As Long
Dim hFile As Long
Dim sBuffer As String
Dim Ret As Long
Dim oldret As Long
Dim oldbuffer As String
Dim bytesreadint As Long
'Create a buffer for the file we're going to download
sBuffer = Space(1000)
'Create an internet connection
hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)
'Open the url
hFile = InternetOpenUrl(hOpen, sUrl, vbNullString, ByVal 0&, INTERNET_FLAG_RELOAD, ByVal 0&)
'Read a1000 bytes of the file
oldbuffer = ""
Do
oldbuffer = sBuffer
InternetReadFile hFile, sBuffer, 1000, Ret
If Ret <> 1000 Then 'ret will not return 1000 if it cant i.e if there are less bytes than that left, instead, it will return the amount left.
bytesreadint = bytesreadint + Ret
Exit Do
Else
bytesreadint = bytesreadint + 1000
End If
Loop
'clean up
InternetCloseHandle hFile
InternetCloseHandle hOpen
'Show our file
GetFileLength = bytesreadint
End Function