Results 1 to 3 of 3

Macro to Copy .xlsm workbooks from folder and sub-solder

Threaded View

  1. #1
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2021
    Posts
    2,776

    Macro to Copy .xlsm workbooks from folder and sub-solder

    I have written code to copy .xlsm files from folder and subfolder "C:\GL Reports" to C:\Old GL Reports"


    When running my macro no .xlsm ae copied to C:\Old GL Reports"


     Sub Copyfiles()
        Application.ScreenUpdating = False
        Application.DisplayAlerts = False
    
        Dim FSO As Object, fld As Object
        Dim fname As Object
        Dim sbfol As Object
        Dim fpath As String, xpath As String
        Dim tpath As String
    
        fpath = "C:\GL Reports"
        tpath = "C:\Old GL Reports"
        If Right(fpath, 1) <> "\" Then fpath = fpath & "\"
        If Right(tpath, 1) <> "\" Then tpath = tpath & "\"
    
        Set FSO = CreateObject("Scripting.FileSystemObject")
        Set fld = FSO.getfolder(fpath)
        If FSO.folderExists(fld) Then
            For Each fname In fld.Files
                If Mid(fname.Name, InStrRev(fname.Name, ".") + 1) = "xlsm" Then
    
                    xpath = fname.Path
    
                    FSO.movefile Source:=xpath, Destination:=tpath
                End If
            Next
    
            For Each sbfol In FSO.getfolder(fpath).subfolders
                For Each fname In sbfol.Files
                    If Mid(fname.Name, InStrRev(fname.Name, ".") + 1) = "xlsx" Then
    
                        xpath = fname.Path
    
                        FSO.movefile Source:=xpath, Destination:=tpath
                    End If
                Next
            Next
        End If
    End Sub

    It would be appreciated if someone could kindly amend my code
    Last edited by Howardc1001; 10-28-2019 at 03:54 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Macro to list and open .xlsm files in folder and sub-folder
    By Howardc1001 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-24-2019, 07:35 PM
  2. [SOLVED] Copy Range from multiple Workbooks in folder, to Summary Workbook also in same folder?
    By xlyfe in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-24-2018, 01:22 PM
  3. [SOLVED] Macro that combines serveral workbooks stops on .xlsm files
    By Happytab in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-05-2017, 09:05 AM
  4. Split .xlsm workbook into multiple xlsm workbooks w/ 1 tab each
    By JenBR in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 01-23-2014, 07:05 PM
  5. VBA Copy macro-enabled worksheets to all workbooks in folder
    By Kahmed2R in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-30-2013, 09:59 AM
  6. create a compressed folder or zipped folder then copy workbooks to it.
    By Ironman in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-04-2012, 03:56 PM
  7. Macro - Copy 3 cells from all workbooks in a folder
    By misterzr in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-24-2010, 09:43 AM

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