VBA Make Sub-Folders into Main Folder

Pinaceous

Well-known Member
Joined
Jun 11, 2014
Messages
1,113
Office Version
  1. 365
Platform
  1. Windows
Hi All!

I have a sub that Creates a Folder and sticks a document into it and places it onto my desktop! (Finally!)

VBA Code:
Sub CreateFolders()
'(01) Documents

Dim FSO As Object, sourceFolder As Object, file As Object

  Dim sPath As String, sMain As String, sFolder As String
  Dim i As Long

    Set FSO = CreateObject("Scripting.FileSystemObject")
    sPath = CreateObject("WScript.Shell").SpecialFolders("Desktop")
    sMain = sPath & "\" & ThisWorkbook.Sheets(1).Range("B11").Value
 
  If Dir(sMain, vbDirectory) <> "" Then 'if the folder exists
  'Do nothing
    MsgBox "Duplicate Folders!"
    'MsgBox Application.UserName & " Duplicate Folders!"
    'MsgBox Environ("Temp") & " Hello!"
 
  Exit Sub
 
  Else ' 'if the folder not exists
      MkDir sMain
        FSO.copyFile Source:="F:\MISC\IMPORT.pdf", Destination:=sMain & "\IMPORT.pdf"
 

    End If
 
End Sub

I have a secondary code, which also works wonderfully and creates folders based upon cell designation in my workbook:

VBA Code:
Sub MakesFolders()
 
Dim FldrName As String
 
On Error Resume Next
 
For i = 11 To 23
   FldrName = Cells(i, 3).Value
   MkDir "C:\Users\Desktop\" & FldrName
 
Next i
 
End Sub

My question is, how can I combine these two codes in order to allow the newly created folders by the second code to be placed into the 1st code?

For example, how can I create a condition to allow the
VBA Code:
 Sub MakesFolders()
to be placed into the folder created by the
VBA Code:
 Sub CreateFolders()
??

Please let me know, if you have any suggestions!

Thanks,
~Pin
 
Last edited:

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Forum statistics

Threads
1,214,792
Messages
6,121,612
Members
449,039
Latest member
Mbone Mathonsi

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