Option ExplicitPrivate Declare Function InternetGetConnectedStateEx Lib "wininet.dll" _
        Alias "InternetGetConnectedStateExA" _
        (ByRef lpdwFlags As Long, _
        ByVal lpszConnectionName As String, _
        ByVal dwNameLen As Long, _
        ByVal dwReserved As Long _
        ) As LongPrivate Declare Function InternetOpen Lib "wininet.dll" 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 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 InternetReadFile Lib "wininet.dll" ( _
                                                ByVal hFile As Long, _
                                                ByVal sBuffer As String, _
                                                ByVal lNumBytesToRead As Long, _
                                                lNumberOfBytesRead As Long) As Integer
                                                
Private Declare Function InternetCloseHandle Lib "wininet.dll" ( _
                                                ByVal hInet As Long) As Integer'Private Enum EIGCInternetConnectionState
'        INTERNET_CONNECTION_MODEM = &H1&
'        INTERNET_CONNECTION_LAN = &H2&
'        INTERNET_CONNECTION_PROXY = &H4&
'        INTERNET_RAS_INSTALLED = &H10&
'        INTERNET_CONNECTION_OFFLINE = &H20&
'        INTERNET_CONNECTION_CONFIGURED = &H40&
'End EnumPublic Function InternetConnected() As Boolean
    
    Dim dwFlags As Long
    Dim sNameBuf As String
'    Dim lR As Long
    Dim iPos As Long
    
    sNameBuf = String$(513, 0)
    InternetConnected = (InternetGetConnectedStateEx(dwFlags, sNameBuf, 512, 0&) = 1)
End FunctionPrivate Function GetUrlSource(sURL As String) As String
    Dim sBuffer As String * 256, iResult As Integer, sData As String
    Dim hInternet As Long, hSession As Long, lReturn As Long    'get the handle of the current internet connection
    hSession = InternetOpen("vb wininet", 1, vbNullString, vbNullString, 0)
    'get the handle of the url
    If hSession Then
        hInternet = InternetOpenUrl(hSession, sURL, vbNullString, 0, &H4000000, 0)
    End If
    'if we have the handle, then start reading the web page
    If hInternet Then
        'get the first chunk & buffer it.
        iResult = InternetReadFile(hInternet, sBuffer, 256, lReturn)
        sData = sBuffer
        'if there's more data then keep reading it into the buffer
        Do While lReturn <> 0
            iResult = InternetReadFile(hInternet, sBuffer, 256, lReturn)
            sData = sData + Mid(sBuffer, 1, lReturn)
        Loop
    End If
   
    'close the URL
    iResult = InternetCloseHandle(hInternet)     GetUrlSource = VBA.Replace(sData, VBA.Chr(0), "")
End Function