Je comptai crée une constante pour ne pas crée l'object "obj_http" a chaque fois que j’appelle la fonction GetHTML
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 Const WINHTTP_REQUEST_VERSION = "WinHttp.WinHttpRequest.5.1" Private Const base_url As String = "xxxxxxxxxx" Public Const obj_http As Object = CreateObject(WINHTTP_REQUEST_VERSION) 'erreur de compilation Function GetHTML(ByVal suite_url As String) As HTMLDocument obj_http.Open "GET", base_url & suite_url, False obj_http.Send If obj_http.Status = 200 Then Dim HTMLDoc As HTMLDocument Set HTMLDoc = New HTMLDocument SaveHTMLToFile base_url & suite_url, obj_http.ResponseText HTMLDoc.body.innerHTML = obj_http.ResponseText Set GetHTML = HTMLDoc Else Set GetHTML = Nothing End If Set obj_http = Nothing End Function
mais j'ai une erreur de compilation : type de données incorrect pour une constante
j'ai bien coché la réference WinHTTP Services,version 5.1
Du coup j'ai fait ceci :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 Function CreateWinHttpRequest() As Object Dim objHTTP As Object Set objHTTP = CreateObject(WINHTTP_REQUEST_VERSION) Set CreateWinHttpRequest = objHTTP End Function
Partager