Est-il possible, dans une macro VBA Excel 2007 de créer un string (ou un
fichier txt) contenant le code d'une page web?
Si oui, quelle est la méthode à utiliser?
Cette action est irreversible, confirmez la suppression du commentaire ?
Signaler le commentaire
Veuillez sélectionner un problème
Nudité
Violence
Harcèlement
Fraude
Vente illégale
Discours haineux
Terrorisme
Autre
Daniel.j
Bonjour Avec cette macro 'Recupere le code source d'une URL Sub GetSourceCode() Const URL As String = "http://dj.joss.free.fr" ' Create an Http object (use any of the four objects) Dim Http As Object 'Set Http = CreateObject("Microsoft.XMLHTTP") 'Set Http = CreateObject("MSXML2.ServerXMLHTTP") 'Set Http = CreateObject("WinHttp.WinHttpRequest") Set Http = CreateObject("WinHttp.WinHttpRequest.5.1") Http.Open "GET", URL, False Http.Send Call BinaryToString(Http.ResponseBody, "c:ajeterhtmlSource.txt") Set Http = Nothing End Sub
Private Sub BinaryToString(Binary, FileName$, Optional CharSet = "") Dim BinaryStream As Object, BinaryToString As String Set BinaryStream = CreateObject("ADODB.Stream") With BinaryStream .Type = 1 ' (Type Binary) .Open .Write Binary .Position = 0 .Type = 2 ' (Type Text) .CharSet = "us-ascii" ' Specify charset For the source text (unicode) data. If Len(CharSet) Then .CharSet = CharSet BinaryToString = .ReadText .WriteText BinaryToString .SaveToFile FileName, 2 End With Set BinaryStream = Nothing End Sub
-- Daniel FAQ MPFE http://dj.joss.free.fr/faq.htm
VBAXL http://dj.joss.free.fr/
"Mikel" a écrit dans le message de news: 485e1844$0$875$
Bonjour à tous!
Est-il possible, dans une macro VBA Excel 2007 de créer un string (ou un fichier txt) contenant le code d'une page web? Si oui, quelle est la méthode à utiliser?
Cordialement, Mikel
Bonjour
Avec cette macro
'Recupere le code source d'une URL
Sub GetSourceCode()
Const URL As String = "http://dj.joss.free.fr"
' Create an Http object (use any of the four objects)
Dim Http As Object
'Set Http = CreateObject("Microsoft.XMLHTTP")
'Set Http = CreateObject("MSXML2.ServerXMLHTTP")
'Set Http = CreateObject("WinHttp.WinHttpRequest")
Set Http = CreateObject("WinHttp.WinHttpRequest.5.1")
Http.Open "GET", URL, False
Http.Send
Call BinaryToString(Http.ResponseBody, "c:ajeterhtmlSource.txt")
Set Http = Nothing
End Sub
Private Sub BinaryToString(Binary, FileName$, Optional CharSet = "")
Dim BinaryStream As Object, BinaryToString As String
Set BinaryStream = CreateObject("ADODB.Stream")
With BinaryStream
.Type = 1 ' (Type Binary)
.Open
.Write Binary
.Position = 0
.Type = 2 ' (Type Text)
.CharSet = "us-ascii"
' Specify charset For the source text (unicode) data.
If Len(CharSet) Then .CharSet = CharSet
BinaryToString = .ReadText
.WriteText BinaryToString
.SaveToFile FileName, 2
End With
Set BinaryStream = Nothing
End Sub
--
Daniel
FAQ MPFE
http://dj.joss.free.fr/faq.htm
VBAXL
http://dj.joss.free.fr/
"Mikel" <mikel.d@wanadoo.fr> a écrit dans le message de news:
485e1844$0$875$ba4acef3@news.orange.fr...
Bonjour à tous!
Est-il possible, dans une macro VBA Excel 2007 de créer un string (ou un
fichier txt) contenant le code d'une page web?
Si oui, quelle est la méthode à utiliser?
Bonjour Avec cette macro 'Recupere le code source d'une URL Sub GetSourceCode() Const URL As String = "http://dj.joss.free.fr" ' Create an Http object (use any of the four objects) Dim Http As Object 'Set Http = CreateObject("Microsoft.XMLHTTP") 'Set Http = CreateObject("MSXML2.ServerXMLHTTP") 'Set Http = CreateObject("WinHttp.WinHttpRequest") Set Http = CreateObject("WinHttp.WinHttpRequest.5.1") Http.Open "GET", URL, False Http.Send Call BinaryToString(Http.ResponseBody, "c:ajeterhtmlSource.txt") Set Http = Nothing End Sub
Private Sub BinaryToString(Binary, FileName$, Optional CharSet = "") Dim BinaryStream As Object, BinaryToString As String Set BinaryStream = CreateObject("ADODB.Stream") With BinaryStream .Type = 1 ' (Type Binary) .Open .Write Binary .Position = 0 .Type = 2 ' (Type Text) .CharSet = "us-ascii" ' Specify charset For the source text (unicode) data. If Len(CharSet) Then .CharSet = CharSet BinaryToString = .ReadText .WriteText BinaryToString .SaveToFile FileName, 2 End With Set BinaryStream = Nothing End Sub
-- Daniel FAQ MPFE http://dj.joss.free.fr/faq.htm
VBAXL http://dj.joss.free.fr/
"Mikel" a écrit dans le message de news: 485e1844$0$875$
Bonjour à tous!
Est-il possible, dans une macro VBA Excel 2007 de créer un string (ou un fichier txt) contenant le code d'une page web? Si oui, quelle est la méthode à utiliser?