Results 1 to 6 of 6

Thread: Macro To Close All CSV Files

  1. #1
    Senior Member
    Join Date
    Apr 2012
    Posts
    193
    Rep Power
    13

    Macro To Close All CSV Files

    I would like a macro to close all open .csv files

    macro tto close all csv files

  2. #2
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    Use this

    Code:
    Sub CloseCSV()
    
        Dim wbk As Workbook
        
        For Each wbk In Workbooks
            If wbk.FileFormat = 6 Then
                wbk.Close 0
            End If
        Next wbk
        
    End Sub
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  3. #3
    Senior Member
    Join Date
    Apr 2012
    Posts
    193
    Rep Power
    13
    Hi

    Thanks for the help, much appreciated

  4. #4
    Senior Member
    Join Date
    Apr 2012
    Posts
    193
    Rep Power
    13
    Hi ExcelFox

    I while back you provided me with code to close csv files that are open.It worked previosly, but when using it, one of the csv files won't close called

    BR1 SalesLedgerOutstandingTransactions.csv

    It would be appreciated if you would assist



    Code:
      For Each wbk In Workbooks
            If wbk.FileFormat = 6 Then
                wbk.Close 0
            End If
        Next wbk
        
    End Sub

  5. #5
    Senior Member
    Join Date
    Jun 2012
    Posts
    337
    Rep Power
    13
    Check the fiteformat of that file.

  6. #6
    Senior Member
    Join Date
    Apr 2012
    Posts
    193
    Rep Power
    13
    Thanks for the reply

    I sorted out the problem, by amending the code slightly


    Code:
     For Each wbk In Workbooks
            If wbk.FileFormat = xlcsv Then
                wbk.Close 
            End If
        Next wbk
        
    End Sub

Similar Threads

  1. Saving and Running Macro For Multiple Files / Users
    By Charles_ in forum Excel Help
    Replies: 1
    Last Post: 01-07-2013, 09:10 AM
  2. export all worksheets to separate csv files
    By rabidfly in forum Excel Help
    Replies: 4
    Last Post: 11-18-2012, 02:11 PM
  3. Macro to export sheet as CSV
    By Howardc in forum Excel Help
    Replies: 2
    Last Post: 07-25-2012, 08:59 PM
  4. Macro to create files as per the contents in a column
    By Praveen Bj in forum Excel Help
    Replies: 1
    Last Post: 07-05-2012, 09:07 PM
  5. Collate Data from csv files to excel sheet
    By dhiraj.ch185 in forum Excel Help
    Replies: 16
    Last Post: 03-06-2012, 07:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •