+ Reply to Thread
Results 1 to 4 of 4

Copying files and folders

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-02-2013
    Location
    england
    MS-Off Ver
    Excel 2007
    Posts
    112

    Question Copying files and folders

    Hi,

    There is a folder named "STAR1" in C:\VALUES\ABSTRACTS\VALUES\STAR1

    There is a file named "TOTALS.XLSM" in (C:\VALUES\ABSTRACTS\VALUES\STAR1\TOTALS.XLSM)


    At "sheet1" of "TOTALS.XLSM" there is a value "1" at cell "K2"



    Now, i am looking for a solution to make about 100 copies of "STAR1" and rename each of the copies starting from

    "STAR2" in (C:\VALUES\ABSTRACTS\VALUES\STAR2), "STAR3" in (C:\VALUES\ABSTRACTS\VALUES\STAR3) until "STAR100".

    And also increase the values at cell "K2" in "TOTALS.XLSM" by 1. so that for folder "STAR2" the value of cell "K2" would be 2 and for "STAR3" it would be 3 etc.

    Thanks

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Copying files and folders

    THis should do it:
    Option Explicit
    
    Sub MakingCopies()
    Dim NUM As Long, fPATH As String, wb As Workbook
    
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    fPATH = "C:\VALUES\ABSTRACTS\VALUES\"                           'the master folder
    Set wb = Workbooks.Open(fPATH & "STAR1\Totals.xlsm", False)     'the main workbook to copy
    On Error Resume Next
    
    For NUM = 2 To 100
        MkDir fPATH & "STAR" & NUM
        With wb.Sheets("Sheet1").Range("K2")
            .Value = .Value + 1
        End With
        wb.SaveCopyAs fPATH & "STAR" & NUM & "\" & wb.Name
        DoEvents
    Next NUM
    
    wb.Close False
    Application.ScreenUpdating = True
    
    End Sub
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,784

    Re: Copying files and folders

    Perhaps something like this?

    In order to make it simple I would suggest you add this macro to the file "TOTALS.XLSM" in folder "STAR1" and that "Sheet1" is the active sheet.

    Option Explicit
    
    Sub MakeM()
    
    Dim i As Integer
    Dim sPath As String
    
    sPath = "C:\VALUES\ABSTRACTS\VALUES\STAR"
    
    For i = 2 To 100
    
    Range("K2") = i
    
    MkDir sPath & i
    
    ActiveWorkbook.SaveAs Filename:=sPath & i & "\" & "Totals.xlsm"
    
    Next
    
    ActiveWorkbook.Close False
    
    End Sub

  4. #4
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,784

    Re: Copying files and folders

    Thanks for feed back and rep.

    Alf

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Create folders and save text files to these folders
    By bloomingcarrot in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-03-2014, 08:14 PM
  2. Replies: 0
    Last Post: 10-15-2014, 04:37 AM
  3. Use Excel VBA to Copy multiple files from different source folders to different folders
    By mm1234mail in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-12-2014, 01:17 PM
  4. Replies: 1
    Last Post: 09-12-2013, 09:23 PM
  5. copying files between folders
    By mqdias in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-26-2007, 09:37 AM

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