Oakwoodbespoke
New Member
- Joined
- Jun 27, 2023
- Messages
- 12
- Office Version
- 365
- Platform
- Windows
Hi,
I'm trying to do the following:
I have a list of job numbers with their relevant site addresses (I have made them as one with CONCATENATE in Column E)
I have managed to get things to work so you can select cells in Column E and it will create new folders within a Folder named "New Folder 2" on the desk top
What I would like it to do is once the new folders are created it copies a Excell workbook from a specified location and adds it to each newly created folder.
Thanks in advance for any help
Sub MakeFolders()
Dim dirName As String
Dim selectedRange As Range
Dim cell As Range
Dim i As Long
' Prompt user to select a range of cells
Set selectedRange = Application.InputBox("Select a range of cells:", "Select Range", Type:=8)
' Check if a range was selected
If Not selectedRange Is Nothing Then
' Create folders based on cell values
On Error Resume Next ' Enable error handling
For Each cell In selectedRange
dirName = cell.Value
MkDir "c:\Users\xxusernamexx\Desktop\New Folder 2\" & dirName
Next cell
On Error GoTo 0 ' Reset error handling
MsgBox "Folders have been created successfully!", vbInformation
Else
MsgBox "No range selected. Operation cancelled.", vbInformation
End If
End Sub
I'm trying to do the following:
I have a list of job numbers with their relevant site addresses (I have made them as one with CONCATENATE in Column E)
I have managed to get things to work so you can select cells in Column E and it will create new folders within a Folder named "New Folder 2" on the desk top
What I would like it to do is once the new folders are created it copies a Excell workbook from a specified location and adds it to each newly created folder.
Thanks in advance for any help
Sub MakeFolders()
Dim dirName As String
Dim selectedRange As Range
Dim cell As Range
Dim i As Long
' Prompt user to select a range of cells
Set selectedRange = Application.InputBox("Select a range of cells:", "Select Range", Type:=8)
' Check if a range was selected
If Not selectedRange Is Nothing Then
' Create folders based on cell values
On Error Resume Next ' Enable error handling
For Each cell In selectedRange
dirName = cell.Value
MkDir "c:\Users\xxusernamexx\Desktop\New Folder 2\" & dirName
Next cell
On Error GoTo 0 ' Reset error handling
MsgBox "Folders have been created successfully!", vbInformation
Else
MsgBox "No range selected. Operation cancelled.", vbInformation
End If
End Sub