0

I have a file named control.xlsx and want to make macro in this file so control other files in same directory.

I tried like below,

Sub control()

  name = Dir(ActiveWorkbook.path & "\*.xlsx")
  Do While name <> ""
   FileCopy name, ActiveWorkbook.Path & "\new" & "\" & name
  Loop

End Sub

but it doesn't work.. anybody who can help me! I want to modify the copied excel files next. any tips!

6
  • 3
    Note that "it doesn't work" is a completely useless error description. Also make sure that ActiveWorkbook is exactly what you want and not ThisWorkbook they often get mixed up. • I also recommend to activate Option Explicit: In the VBA editor go to ToolsOptionsRequire Variable Declaration. Commented Jan 17, 2019 at 8:07
  • 1
    Duplicate of stackoverflow.com/questions/16943003/… Commented Jan 17, 2019 at 8:07
  • Are you sure the full destination path exists? Commented Jan 17, 2019 at 8:10
  • 1
    Possible duplicate of VBA to copy a file from one directory to another Commented Jan 17, 2019 at 8:11
  • Why not just duplicate the folder (with contents...) Commented Jan 17, 2019 at 8:38

1 Answer 1

1

Your code is almost OK.

     Sub control()
        name = Dir(ActiveWorkbook.path & "\*.xlsx")
        Do While name <> ""
           FileCopy name, ActiveWorkbook.Path & "\new" & "\" & name
           name = Dir()
        Loop
     End Sub
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.