PDA

View Full Version : Create Text File with FSO and VBA CreateTextFile



Wirgis
10-01-2018, 02:24 AM
Hi,

Have a problem with Write data from the HTTP to text file.
Below part of application in VBA:


Dim objXMLHTTP, xml
targetURL = https://cvpp.eviesiejipirkimai.lt/?Query=Lietuvos+kariuomen%C4%97%09%09%09%09%09%09%09%09%09%09%09%09&OrderingType=1&OrderingDirection=0&TypeContractId=&ProcedureSearchTypeId=&NoticeType=&PublicationType=&IncludeExpired=true&IncludeExpired=false&Cpvs=&TenderId=&DeadlineFromDate=&DeadlineToDate=&PublishedFromDate=2018-08-29&PublishedToDate=2018-09-27&PageNumber=1&PageSize=90
Set xml = CreateObject("Microsoft.XMLHTTP")
Set fso = CreateObject("Scripting.FileSystemObject")
xml.Open "GET", targetURL, False
xml.setRequestHeader "Cache-Control", "no-cache"
xml.Send
Set tfile = fso.CreateTextFile("C:\Desktop\failas.asp", True)
tfile.Write xml.ResponseText ' Have Run-time error '5': Invalid procedure call or argument
Set fso = Nothing
tfile.Close

Sorry for long "targetURL", just you can try real web site and data.
After change last parameter "PageSize=80" have a good result for text file "failas.asp" without "Error '5'".

What I have did in wrong way?


Best regards,
Wirgis

Aussiebear
03-23-2024, 10:45 PM
Yet again another thread posted to the wrong forum.

arnelgp
03-23-2024, 11:32 PM
try:


im objXMLHTTP, xml
targetURL = https://cvpp.eviesiejipirkimai.lt/?Q...=1&PageSize=90 (https://cvpp.eviesiejipirkimai.lt/?Query=Lietuvos+kariuomen%C4%97%09%09%09%09%09%09%09%09%09%09%09%09&OrderingType=1&OrderingDirection=0&TypeContractId=&ProcedureSearchTypeId=&NoticeType=&PublicationType=&IncludeExpired=true&IncludeExpired=false&Cpvs=&TenderId=&DeadlineFromDate=&DeadlineToDate=&PublishedFromDate=2018-08-29&PublishedToDate=2018-09-27&PageNumber=1&PageSize=90)
Set xml = CreateObject("Microsoft.XMLHTTP")
Set fso = CreateObject("Scripting.FileSystemObject")
xml.Open "GET", targetURL, False
xml.setRequestHeader "Cache-Control", "no-cache"
xml.Send
Set tfile = fso.CreateTextFile(Environ$("UserProfile") & "\Desktop\failas.asp", True)
tfile.Write xml.ResponseText ' Have Run-time error '5': Invalid procedure call or argument
Set fso = Nothing
tfile.Close