excel - How to get file extension using Microsoft XMLHTTP using VBA -


I am using the following simple code to download and save some files from the Internet. The server that I am sometimes connecting to excel files and generates text files for the second time, I know that if theres want to find out in any possible way what file extension then download it with the proper detail Can be done? Right now I save files all of the files in the form of text and if the file returns the file excellence then the downloaded file will be useless (as it is saved as a txt file and I change the extension manually ). Thanks guys

  Dim myURL String Dim as WinHttpReq Object FSD string as myURL = "Sample URL" WinHttpReq = CreateObject ("Microsoft.XMLHTTP") WinHttpReq.Open "GET" , As myURL, wrong WinHttpReq.Send myURL = WinHttpReq.ResponseBody if WinHttpReq.Status = 200 then Ostream = Create Object ("ADODB.Stream") ostream. Open Ostream Type = 1 ostream.Write WinHttpReq.ResponseBody Ostream. SaveToFile (FP & "& amp; 1; & amp; & amp;; - & amp;; C2 & amp;" .txt "), 2 oStream Close End then End Sub  

Before WinHttpReq.Open "GET", myUrl, false You can try to open the header and see the mime type of your file before downloading: WinHttpReq.Open "head", myUrl, false WinHttpReq.Send MyHeader = WinHttpReq.getAllResponseHeaders () 'Scan MyHeader here to find your file mime type ... < / Html>

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -