Create Folder VBA Code Not Working

hkydad

Board Regular
Joined
May 16, 2013
Messages
66
Office Version
  1. 365
Platform
  1. Windows
I have the code below but when I run the code, the folders on my active worksheet are not being created and I'm not sure why.

The folder names I want to create are below and are all in column A beginning with row 1. Any assistance would be greatly appreciated.
01-2024
02-2024
03-2024

Private Sub CreateFolder()


Dim xdir As String
Dim fso
Dim fsoSub
Dim lstrow As Long
Dim i As Long
Dim xdirsubfolder As String
Set fso = CreateObject("Scripting.FileSystemObject")
Set fsoSub = CreateObject("Scripting.FileSystemObject")
lstrow = ActiveSheet.Cells(ActiveSheet.Rows.Count, "A").End(xlUp).Row
Application.ScreenUpdating = True
For i = 1 To lstrow
xdir = "J:\_Dvision\Group\Tim\2024\" & Range("A" & i).Value
xdirsubfolder = "J:\_Division\Group\Tim\2024\" & Range("A" & i).Value & "\" & Range("A" & i).Offset(0, 3)

If Not fso.FolderExists(xdir) Then
fso.CreateFolder (xdir)
End If

If Not fsoSub.FolderExists(xdirsubfolder) Then
fsoSub.CreateFolder (xdirsubfolder)
End If


Next
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
File name is the issue.
1701879439774.png
 
Upvote 1
Solution
Thank you for your assistance. Never thought that a - would cause such a problem.
 
Upvote 0

Forum statistics

Threads
1,215,097
Messages
6,123,076
Members
449,094
Latest member
mystic19

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