Creat folder and subfolder

webdevptg

Board Regular
Joined
May 2, 2019
Messages
51
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
  2. Web
Hi!

I am implementing a system that allows you to create a folder and subfolder based on the cell values.

There will be a root folder, inside this there will be a folder with the year (based on the date of cell B5), within this folder it creates a subfolder for the country based on the list available in cell B7, and finally creates the subfolder with the process number. Whenever there is a folder with the same process number, it will give a message if you want to delete and create a new one.

Download Sample: CreatFolder.xlsm

Capturar.PNG


Thanks!
 

Attachments

  • Capturar.PNG
    Capturar.PNG
    6.4 KB · Views: 4

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
And what is your question?
 
Upvote 0
Sorry, I forgot

When creat a second process with a same year or same country, gives an error with a message "Path/File access error"

Oc
And what is your question?
 
Upvote 0
Ok, how about
VBA Code:
Sub CreatFolder()
    'Variable declaration
    Dim wsBD As Worksheet
    Dim folderRoot, folderYear, folderCountry, folderProcess, pastaSeparador As String
       
    Dim blfolderRoot, blfolderYear, blfolderCountry, blfolderProcess As Boolean
    
    'Initialization variables
    Set wsBD = Sheets("Sheet1")
    
    folderRoot = wsBD.Range("B2").Value
    folderYear = folderRoot & Application.PathSeparator & Year(wsBD.Range("B5").Value)
    folderCountry = folderYear & Application.PathSeparator & wsBD.Range("B7").Value
    folderProcess = folderCountry & Application.PathSeparator & wsBD.Range("B9").Value
    
    
    blfolderRoot = Dir(folderRoot, vbDirectory) = ""
    blfolderYear = Dir(folderYear, vbDirectory) = ""
    blfolderCountry = Dir(folderCountry, vbDirectory) = ""
    blfolderProcess = Dir(folderProcess, vbDirectory) = ""

    'Checks if there is a root folder (network connection)
    If blfolderRoot Then MkDir (folderRoot)
    If blfolderYear Then MkDir (folderYear)
    If blfolderCountry Then MkDir (folderCountry)
    If blfolderProcess Then MkDir (folderProcess)
    
End Sub
 
Upvote 0
Very interesting subroutine. You never cease to amaze!
(Side comment: I especially loved "pastaSeparador")
 
Upvote 0
That's actually the OP's code, I just changed the bit at the end with the if statements. ;)
 
Upvote 0
That's actually the OP's code, I just changed the bit at the end with the if statements. ;)
I thought you were doing some tongue in cheek statement.
Don't think the OPs code works without a string assignment for that variable...true?
 
Upvote 0
The code works fine...

The code already has more instructions, copies a folder shared on the network with other subfolders and with some word and excel files renamed.

Finally, I need to do the following, the word files are institutional models, I need to pass the contents of some cells to specific areas of the documents and also an image for the footer ...

I've been looking here on the forum, but I just find putting content in an empty file and the image at the beginning of the document ...

Any tips ???
 
Upvote 0
As that is a totally different question, you will need to start a new thread. Thanks
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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