Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems using wininet.dll from VBA/excel

Status
Not open for further replies.

grebo75

Programmer
Jan 10, 2007
1
GB
Hi, I'm reading a web site from VBA but I'm having trouble closing the connection aftwerwards.

hOpen = InternetOpen("", _
INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY, _
vbNullString, _
vbNullString, _
0&)
hFile = InternetOpenUrl(hOpen, sURL, "", 0, INTERNET_FLAG_RELOAD, ByVal 0&)

sBuffer = ""
Do
readOk = InternetReadFile(hFile, smallBuff, Length, Ret)
If readOk Then sBuffer = sBuffer + Left(smallBuff, Ret)
Loop While readOk And Ret > 0
If (InternetCloseHandle(hFile)) = False Then
MsgBox "File close failed"
End If
If Err.LastDllError <> 0 Then
MsgBox "File close failed-" & Err.LastDllError
End If


Trying to call InternetCloseHandle for hFile always returns true but Err.LastDllError is always set to 6.

What am I doing wrong ?

I then close hOpen successfully, but any further attempt to run this section of code freezer, presumably beacuse the close of hFile didn't work correctly.
Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top