Results 1 to 15 of 15

Loop a macro through the multiple files

Threaded View

  1. #10
    Registered User
    Join Date
    11-08-2014
    Location
    Malaysia
    MS-Off Ver
    2010
    Posts
    84

    Re: Loop a macro through the multiple files

    Could you please help me to solve this issue?
    This loop for my macro shows me 'run time error 1004' in Line 16.

    Sub Macro_data_L3()
    
        ' Set folder containing CSV files
        Const strFOLD As String = "C:\Users\XX\Desktop\"
        
        ' Set formula to be used
        Const strFORMULA As String = "GET.DOCUMENT(88)"
        
        Dim strFile As String
        Dim wkbCsv As Workbook
        Dim lngLastRow As Long
        
        strFile = Dir$(strFOLD & "*.csv", vbNormal)
        
        Do While strFile <> vbNullString
            Set wkbCsv = Application.Workbooks.Open(Filename:=strFile)
            
            With wkbCsv.Worksheets(1)
                .Rows("1").Delete
                
                With .Columns("B")
                    .Clear
                    .Insert
                End With
                
                .Columns("A").TextToColumns _
                    Destination:=.Range("A1"), _
                    Other:=True, _
                    OtherChar:=Chr(47), _
                    FieldInfo:=Array( _
                        Array(1, xlGeneralFormat), _
                        Array(2, xlGeneralFormat), _
                        Array(3, xlGeneralFormat))
                
                .Columns("A:C").ClearFormats
                .Range("A1:C1").Value = Array("Day", "Month", "Year")
                
                .Columns("C").Cut
                .Columns("A").Insert
                .Columns("B").Cut
                .Columns("D").Insert
                .Columns("A").Insert
                
                .Range("A1").Value = "ID"
                lngLastRow = .Range("B" & .Rows.Count).End(xlUp).Row
                
                .Range("A2:A" & lngLastRow).Formula = _
                    "=SUBSTITUTE(" & strFORMULA & ", "".CSV"", """")"
                    
                strFile = Dir$()
            End With
        Loop
    
    End Sub
    Last edited by Moriexcel; 11-22-2014 at 01:29 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro to open multiple files, remove header and save multiple files in a new format
    By twocircles in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-17-2014, 05:24 PM
  2. Produce multiple PDF files from multiple Excel Files
    By yukipilas in forum Excel General
    Replies: 2
    Last Post: 09-02-2013, 06:52 AM
  3. split text files stored in some location to multiple files based on a condition
    By GIRISH_KH in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-01-2013, 11:32 AM
  4. [SOLVED] Macro to Import Multiple TXT Files into workbook - User to select files/directory
    By saber007 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-15-2013, 08:43 PM
  5. Replies: 0
    Last Post: 11-27-2012, 01:43 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1