Folder Builder

Use the Folder Builder to create code specifying the directory to store files in, optionally using variables in the file creation process. On this page I will explain how to use the different features of Folder Builder:

Note that the third (text-)box shows the code that will be inserted when OK is pressed while the label below it shows what the code actually executed will result in.

Select root folder

To start the Folder Builder, from the Code VBA toolbar, select VBA  »  Folder  »  Folder Builder

Select root folder

You can use the top combo box to select the required root folder from a list which is supported by the Environ$ function. In the screenshot the Temp folder was selected. In the third box we see this is interpreted as

Select root folder

Alternatively, you could simply have selected a fixed folder using the 'Browse for folder' dialog, which can be started using the 'Select Folder' button.

Variable subfolder

Optionally, you can add one or more subfolders to the folder path. This can be specified in the Subfolder textbox as a concatenation (&) of strings and variables available in this procedure.

"report" & intYear & intQtr & "\" & strCustomerName

Append \ to end

When creating a folder string to be used as part of a file path specification, \ checking the 'Append \ to end' will automatically add the & "\".

Function MakeDirMulti

Possibly, the folder you want to use does not yet exist. To ensure it does you may use the VBA MkDir function, or, if there may be a case of multiple levels in subfolders, create those folders using the MakeDirMulti function which is included in Code VBA module modVBAFolderProcedures which is added to your project if you check the 'Add MakeDirMulti function' box. This MakeDirMulti function then can be used as follows:

Dim strFolder As String: strFolder = Environ$("Temp") & "\" & "report" & intYear & intQtr & "\" & strCustomerName
MakeDirMulti strFolder