MkDir and "Path Not Found" Run-time error 76

ChrisCione

Board Regular
Joined
Aug 27, 2008
Messages
92
Office Version
  1. 365
Platform
  1. Windows
As the subject line reads, I am receiving an error when attempting to create multiple folders on a network drive from a list in Excel using the module below. I did this last week, and it worked perfectly (created over 3000 folders in a split second). Today I replicated the action, with a different list, to no avail. Disclaimer: I didn't create the module, nor would I even know how to do so. I found the instructions to do this on a blog at Create folders from a list in Excel.

I tried placing the activeworkbook.path name in the module below and am receiving different errors. Any help is greatly appreciated.

Module:

Sub MakeFolders()
Dim Rng As Range
Dim maxRows, maxCols, r, c As Integer
Set Rng = Selection
maxRows = Rng.Rows.Count
maxCols = Rng.Columns.Count
For c = 1 To maxCols
r = 1
Do While r <= maxRows
If Len(Dir(ActiveWorkbook.Path & "\" & Rng(r, c), vbDirectory)) = 0 Then
MkDir (ActiveWorkbook.Path & "\" & Rng(r, c))
On Error Resume Next
End If
r = r + 1
Loop
Next c
End Sub


EDIT:
Clicking debug highlights this line:

MkDir (ActiveWorkbook.Path & "\" & Rng(r, c))
 
Last edited by a moderator:

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Step thru the code line by line (F8) and check your variable values either by mousing over or asking in immediate window via
?r and hit return. If cursor moves to a new line and shows no value when you do this for any variable, that could be a problem. You could also ask for the value of
?ActiveWorkbook.Path & "\" & Rng(r,c) and see what you get.

FYI, in multi line declarations like Dim maxRows, maxCols, r, c As Integer
only c is an integer; the rest are variants by default because their data type is not specified.

Please post code within code tags (use vba button on posting toolbar). Easier to read & is the only way to maintain indentation.
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,262
Members
452,627
Latest member
KitkatToby

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