Vraag : ServerXMLHTTP in Excel - hoe te om foutenmeldingen op het scherm onbruikbaar te maken?

Hello, postte

david251 hieronder de code - dankt u door de manier - en ik wijzigde het.
I wil onderbrekingen zelf (door opnieuw te proberen) behandelen maar word ik jammer genoeg dit bericht: van

and de programmaeinden. : - (

So ik was benieuwd of is er om het even welke kans om fouten onbruikbaar te maken leid tot een bericht op het scherm.

Thank u zeer voor elke tip.

Christine
" codeBody "
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
Dim objHTTP als ServerXMLHTTP
    Schemerige RetryCnt
    RetryCnt = 3
    Terwijl RetryCnt > 0
        Reeks objHTTP = Nieuwe ServerXMLHTTP
        objHTTP.Open „KRIJGEN“, sURL
        objHTTP.setRequestHeader „gebruiker-Agent“, „Mozilla/4.0 (compatibel systeem; MSIE 6.0; Vensters NT 5.0)“
        objHTTP.send
        objHTTP.WaitForResponse 1
        GetHTMLServerXMLHTTP = objHTTP.responseText
        RetryCnt = RetryCnt - 1
        Als GetHTMLServerXMLHTTP <> "" toen RetryCnt = -1
    Wend
    Als RetryCnt = 0 toen GetHTMLServerXMLHTTP = „1 - onderbreking; kan niet met server“ verbinden
    Plaats objHTTP = niets

Antwoord : ServerXMLHTTP in Excel - hoe te om foutenmeldingen op het scherm onbruikbaar te maken?

Ik ben niet zeker hoe te om het bovengenoemde code werken te krijgen. Dit is code I gebruik om tot Web-pagina's toegang te hebben. Het is derde of van de vierde generatie en vrij robuust. Dit is een volledige codemodule.

'clsInternetConnection
'
De 'klasse verstrekt functionalty om Web-pagina's te lezen.
'
'Uitgevoerd als klassenmodule voor gebruik met om het even welk VB of Vba- project.
'
'© 2008-2010 Kevin M. Jones

Expliciete optie

Privé Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Privé Const INTERNET_FLAG_RELOAD = &H80000000
Privé Const INTERNET_FLAG_PRAGMA_NOCACHE = &H100
Privé Const INTERNET_OPTION_RECEIVE_TIMEOUT zoals lang = 6

Privé Const UserAgent = „VB“

Privé mConnectionHandle zoals lang
Privé mTimeoutSeconds zoals lang

Privé verklaar de Lib van InternetCloseHandle van de Functie „wininet“ (_
     ByRef hInet zoals lang _
  ) Zoals lang

Privé verklaar de Lib „wininet“ alias „InternetOpenA“ van de Functie van InternetOpen (_
     ByVal sAgent als Koord, _
     ByVal lAccessType zoals lang, _
     ByVal sProxyName als Koord, _
     ByVal sProxyBypass als Koord, _
     ByVal lFlags zoals lang _
  ) Zoals lang

Privé verklaar de Lib „wininet“ alias „InternetOpenUrlA“ van de Functie van InternetOpenUrl (_
     hInternetSession van ByVal zoals lang, _
     ByVal lpszUrl als Koord, _
     lpszHeaders van ByVal als Koord, _
     ByVal dwHeadersLength zoals lang, _
     ByVal dwFlags zoals lang, _
     ByVal dwContext zoals lang _
) Zoals lang

Privé verklaar de Lib van InternetReadFile van de Functie „wininet“ (_
     ByVal hFile zoals lang, _
     ByVal sBuffer als Koord, _
     ByVal lNumBytesToRead zoals lang, _
     lNumberOfBytesRead zoals lang _
  ) Als Geheel
 
Privé verklaar de Lib „wininet.dll“ alias „InternetSetOptionA“ van de Functie van InternetSetOption (_
     ByVal hInternet zoals lang, _
     dwOption van ByVal zoals lang, _
     ByRef lpBuffer zoals om het even welk, _
     ByVal dwBufferLength zoals lang _
  ) Zoals lang

Privé SubClass_Initialize ()

  mConnectionHandle = InternetOpen (UserAgent, INTERNET_OPEN_TYPE_PRECONFIG, het vbNullString, het vbNullString, 0)
  Als mConnectionHandle = 0 toen
     MsgBox „Onbekwaam om een verbinding van Internet te openen. De most likely oorzaak is teveel handvatten is gecre�ërd.“
  Beëindig als
  mTimeoutSeconds = 30

Sub van het eind

Privé SubClass_Terminate ()

  InternetCloseHandle mConnectionHandle
     
Sub van het eind

Overheidsfunctie GetWebPage (_
     ByVal URL als Koord, _
     Facultatieve ByVal ProxyUserID als Koord, _
     Facultatieve ByVal ProxyPassword als Koord, _
     Facultatieve ByVal TimeoutSeconds zoals lang _
  ) Als Koord

'Krijg een Web-pagina.
'
'Syntaxis
'
'GetWebPage (URL, [ProxyUserID], [ProxyPassword])
'
'URL - een volledige URL aan een Web-pagina.
'
'ProxyUserID - de gebruiker - identiteitskaart voor de volmachtsserver, als om het even welk. Facultatief. Indien weggelaten
'dan wordt geen volmachtsserver verondersteld.
'
'ProxyPassword - het wachtwoord voor de volmachtsserver. Facultatief. Genegeerd als
'ProxyUserID wordt weggelaten.
'
'TimeoutSeconds - het aantal seconden om tot timing uit te wachten. Facultatief.
'Indien dan weggelaten 30 seconden wordt gebruikt.

  Schemerige ConnectionHandle zoals lang
  Schemerige URLHandle zoals lang
  Schemerige BytesRead zoals lang
  Verduister Resultaat Van Boole
  Verduister InputBuffer als Koord * 10000
  Verduister PageContent als Koord
  Verduister SecurityData als Koord
 
   Als Len (ProxyUserID) > 0 toen
     SecurityData = ProxyUserID
     Als Len (ProxyPassword) > 0 toen
        SecurityData = SecurityData & „: “ & ProxyPassword
     Eind als
     SecurityData = SecurityData & „@“
     URL = vervang (URL, „: /“, „: /“ & SecurityData)
  Eind als
 
   Als TimeoutSeconds = 0 toen TimeoutSeconds = mTimeoutSeconds
 
   Als mConnectionHandle <> 0 toen
     Resultaat = InternetSetOption (mConnectionHandle, INTERNET_OPTION_RECEIVE_TIMEOUT, TimeoutSeconds * 1000, Len (TimeoutSeconds))
     URLHandle = InternetOpenUrl (mConnectionHandle, URL, het vbNullString, 0, INTERNET_FLAG_RELOAD of INTERNET_FLAG_PRAGMA_NOCACHE, 0)
     Als URLHandle <> 0 toen
       
           InputBuffer = vbNullString
           Resultaat = InternetReadFile (URLHandle, InputBuffer, Len (InputBuffer), BytesRead)
           PageContent = PageContent & Weggegaan (InputBuffer, BytesRead)
        Lijn terwijl BytesRead > 0
        InternetCloseHandle URLHandle
     Eind als
  Eind als
 
   GetWebPage = PageContent
 
De Functie van het eind

Het openbare Bezit krijgt ValidInternetConnection () zoals Van Boole

  ValidInternetConnection = mConnectionHandle <> 0

Het Bezit van het eind

Het openbare Bezit krijgt TimeoutSeconds () zoals lang

  TimeoutSeconds = mTimeoutSeconds

Het Bezit van het eind

Het openbare Bezit liet TimeoutSeconds (_
     De Waarde van ByVal zoals lang _
  )

  mTimeoutSeconds = Waarde

Het Bezit van het eind

Kevin
Andere oplossingen  
 
programming4us programming4us