none
Where does .close save to? RRS feed

  • Question

  • Hi, I am using the following code and want to tell the close method where to save to.

    Can anyone help me please?

    Set csv = fso.opentextfile("TOH_Consolidated.csv", 8)
        Lines = Split(f.OpenAsTextStream.ReadAll, vbLf)
       
            For i = 1 To UBound(Lines)
              csv.Write Lines(i) & vbLf
            Next
           
        csv.Close





    • Edited by Gazza101 Wednesday, October 21, 2015 3:11 PM
    Wednesday, October 21, 2015 2:25 PM

Answers

  • Hi, I am using the following code and want to tell the close method where to save to.

    Set csv = fso.opentextfile("TOH_Consolidated.csv", 8)

    You have to put the Drive:\Path portion before the filename in OpenTextfile.

    Andreas.

    • Marked as answer by Gazza101 Wednesday, October 21, 2015 4:26 PM
    Wednesday, October 21, 2015 3:43 PM

All replies

  • Hi, I am using the following code and want to tell the close method where to save to.

    Set csv = fso.opentextfile("TOH_Consolidated.csv", 8)

    You have to put the Drive:\Path portion before the filename in OpenTextfile.

    Andreas.

    • Marked as answer by Gazza101 Wednesday, October 21, 2015 4:26 PM
    Wednesday, October 21, 2015 3:43 PM
  • Hi, thanks for your reply. I don't think it will fix my problem.

    Here is the whole code. so I open a .csv file, if it is the 1st file in the folder I copy it, then add other csv file data to it, and then when I close it I want to tell it where to save to. Hope that makes sense.

    For Each f In fso.GetFolder(CSVFiles & "csv\").Files

              'If this is the first file then copy it
              If isFirst Then
                f.Copy "TOH_Consolidated.csv"
                isFirst = False

              Else

                Set CSV = fso.opentextfile("TOH_Consolidated.csv", 8)
                Lines = Split(f.OpenAsTextStream.ReadAll, vbLf)

                    For i = 1 To UBound(Lines)
                      CSV.Write Lines(i) & vbLf
                    Next

                CSV.Close  <<<< need to be able to save to a set folder of my choice

              End If

        Next

                                                                                

    • Edited by Gazza101 Wednesday, October 21, 2015 4:17 PM
    Wednesday, October 21, 2015 4:15 PM
  • cracked it.

    Andreas you put me on the right track, thanks.

    I needed to add the filepath in both parts of the loop.

    I can go home happy now!!!

    Wednesday, October 21, 2015 4:25 PM
  • FYI, found this via a web search for fso f.copy

    http://www.vbsedit.com/html/c98c7d8c-ba9e-46b7-bc29-14ab1b7f06f3.asp

    Wednesday, October 21, 2015 4:32 PM