PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, August 29, 2022

[FIXED] When using osstream.SaveToFile, is there any way to save the downloaded CSV as a sheet as opposed to a new workbook?

 August 29, 2022     csv, excel, vba     No comments   

Issue

I am currently trying to download a file with a link that outputs a CSV file. I have confirmed that it downloads, but I want it to download into the same workbook, as a separate sheet, without creating another workbook. Is there any parameter/different function that achieves this? My current code is as follows

Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
WinHttpReq.Open "GET", myURL, False
WinHttpReq.Send
myURL = WinHttpReq.ResponseBody
    If WinHttpReq.Status = 200 Then
        Set ostream = CreateObject("ADODB.Stream")
        ostream.Open
        ostream.Type = 1
        ostream.Write WinHttpReq.ResponseBody
        ostream.SaveToFile ("C:\Users\ppppp\Downloads\file1.csv"), 2
        ostream.Close
    End If

End Sub

Solution

How about this:

With Workbooks.Open(myUrl)
    .Sheets(1).copy After:=ThisWorkbook.Worksheets(ThisWorkbook.Worksheets.Count)
    .Close false
End With


Answered By - Tim Williams
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing