create folders with a file in it

snjpverma

Well-known Member
Joined
Oct 2, 2008
Messages
1,584
Office Version
  1. 365
Platform
  1. Windows
I have a list of names and the code number in column A1 to B10. sometimes, less than 10 names are also there.

e.g.:
John254689
James245682
Alisha458213

How can have a folder created with these names and codes.
Folders should look like this
John - 254689
James - 245682 ...

There is a file saved in a particular folder, this file should be copied and pasted in each of the new folder that gets created.
Please assist.
 
In the above code before for...next loop

VBA Code:
    Dim strFile As String
    strFile = "D:\Test VBA\000.xlsx"    ' modify this one
  
    Dim fso As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
  
    Dim oFile As Object
    Set oFile = fso.GetFile(strFile)

Inside the for...next loop right before "Next":

VBA Code:
    If not fso.FileExists(fso.BuildPath(c00, oFile.Name)) Then oFile.Copy fso.BuildPath(c00, oFile.Name)

Right before "End Sub"

VBA Code:
    Set oFile = Nothing
    Set fso = Nothing
this works fine. thank you
 
Upvote 0

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
VBA Code:
    If not fso.FileExists(fso.BuildPath(c00, oFile.Name)) Then oFile.Copy fso.BuildPath(c00, [B]oFile.Name)[/B]

Right before "End Sub"

VBA Code:
    Set oFile = Nothing
    Set fso = Nothing

In the above code before for...next loop

VBA Code:
    Dim strFile As String
    strFile = "D:\Test VBA\000.xlsx"    ' modify this one
  
    Dim fso As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
  
    Dim oFile As Object
    Set oFile = fso.GetFile(strFile)

Inside the for...next loop right before "Next":

VBA Code:
    If not fso.FileExists(fso.BuildPath(c00, oFile.Name)) Then oFile.Copy fso.BuildPath(c00, oFile.Name)

Right before "End Sub"

VBA Code:
    Set oFile = Nothing
    Set fso = Nothing
the file is getting created, but I want the file name also to be the same as folder names.
Please assist.
 
Upvote 0
It should be something like this:

VBA Code:
If not fso.FileExists(fso.BuildPath(c00, fso.GetBaseName(c00 & "." & fso.GetExtensionName(oFile))) Then
    oFile.Copy fso.BuildPath(c00, fso.GetBaseName(c00 & "." & fso.GetExtensionName(oFile))
End If
 
Upvote 0

Forum statistics

Threads
1,214,806
Messages
6,121,672
Members
449,045
Latest member
Marcus05

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top