TL;DR —
MkDircreates one folder level, not a path.MkDir "C:\A\B\C"raiseserror 76ifC:\A\Bdoes not already exist, andMkDiron a folder that already exists raiseserror 75— it is not a silent no-op. "Create this folder" is really "create every missing level, and only where it is absent."
Sub MakeReportsFolder()
MkDir "C:\Reports" ' works only if C:\ exists and C:\Reports does NOT
MkDir "C:\Reports\2026\Q1" ' error 76 — the parent C:\Reports\2026 does not exist yet
End Sub
MkDir looks like the simplest statement in VBA — one keyword, one path. The trouble is that it does
far less than its name suggests. It does not create a path; it creates a single directory whose
parent must already be there. And it does not tolerate a folder that already exists — it stops with an
error. Both surprises come from the same root: MkDir is a one-level operation, and every robust
"create folder" routine is built around that limit.
What you'll learn
- The mental model —
MkDirmakes one level, not a path - Why a nested path raises
error 76, and whyFileSystemObject.CreateFolderdoes not recurse either - Why
MkDiron an existing folder raiseserror 75— and the check that turns it into a safe "ensure exists" - The existence-guarded loop that creates a full path, level by level
- Why a bare
MkDir "Reports"lands underCurDir, not your workbook's folder - The safe "create folder if not exists" pattern for an unattended macro
The mental model: MkDir makes one level, not a path
The key insight is that MkDir creates a single directory entry inside a folder that must already
exist. It is the exact counterpart of typing md at a command prompt with the old, non-recursive
behaviour: it adds one child to a parent, and it expects that parent to be there.
MkDir "C:\Reports"— createsReportsinsideC:\. Fine, becauseC:\exists.MkDir "C:\Reports\2026"— creates2026insideC:\Reports. Works only ifC:\Reportsalready exists.MkDir "C:\Reports\2026\Q1"— needsC:\Reports\2026to exist first, or it fails.
Once you see MkDir as "add one child to an existing parent," both of its famous errors stop being
surprising — they are just the two ways that assumption can be violated: the parent is missing, or the
child is already there.
Error 76: MkDir can't create a nested path (and neither does CreateFolder)
Point MkDir at a path more than one level deep, where an intermediate folder is missing, and it stops:
MkDir "C:\Reports\2026\Q1" ' error 76 — "Path not found" if C:\Reports\2026 is missing
The widespread fix — "just use the FileSystemObject" — does not solve this. CreateFolder is
also a one-level operation; it raises "Path not found" for a missing parent exactly like MkDir:
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CreateFolder "C:\Reports\2026\Q1" ' also fails if C:\Reports\2026 does not exist
Neither built-in creates intermediate folders for you. So building a deep path is inherently a
loop: split the path on the separator and create each level top-down, skipping the ones that already
exist. There is no single call in built-in VBA that does a mkdir -p; you write it. The loop is a few
lines (below), and once you have it, nested creation is a solved problem.
Error 75: MkDir on an existing folder is not a no-op
The second surprise is that MkDir fails when the folder already exists — it does not quietly
succeed:
MkDir "C:\Reports" ' first run: creates it
MkDir "C:\Reports" ' second run: error 75 — "Path/File access error"
This is why a macro that "worked once" crashes on its second run. MkDir is not idempotent, so calling
it unconditionally is a bug. The fix is to check first, with the folder-aware form of
Dir or with FolderExists:
If Dir("C:\Reports", vbDirectory) = "" Then MkDir "C:\Reports" ' create only if absent
The vbDirectory flag makes Dir match folders, so
Dir(path, vbDirectory) = "" means "this folder does not exist." Wrap MkDir in that test and the
statement becomes a safe ensure-exists: it creates the folder the first time and does nothing on
every run after. The cleaner alternative is fso.FolderExists(path), which reads unambiguously and
never touches the shared Dir cursor described in the Dir guide.
The pattern: create a full path, level by level
Putting the two limits together, here is the routine that reliably creates a nested path — the
mkdir -p that VBA does not give you. It walks the path from the root, creating each missing level:
Sub EnsurePath(ByVal fullPath As String)
Dim parts() As String, build As String, i As Long
parts = Split(fullPath, "\")
build = parts(0) ' the drive, e.g. "C:"
For i = 1 To UBound(parts)
build = build & "\" & parts(i)
If Dir(build, vbDirectory) = "" Then MkDir build ' create this level if absent
Next i
End Sub
Call EnsurePath "C:\Reports\2026\Q1" and it creates Reports, then 2026, then Q1, skipping any
that already exist and never raising error 75 or 76. This is the shape almost every production
"create folder" helper takes, because both built-ins force it. The For loop and
the Split do the walking; the Dir(..., vbDirectory) guard does the
safety.
Why a bare folder name lands in the wrong place
MkDir accepts a relative path — a name with no drive or leading \ — and that is where a subtle
bug lives:
MkDir "Reports" ' where does this go? NOT necessarily next to your workbook
A relative path is resolved against CurDir, Excel's current working directory — which is usually
not the folder your workbook is saved in, and which changes whenever a File Open dialog points
somewhere new. So MkDir "Reports" can create the folder in Documents one day and somewhere else the
next. The reliable habit is to build an absolute path from ThisWorkbook.Path:
MkDir ThisWorkbook.Path & "\Reports" ' always next to this workbook
That is the whole subject of the CurDir guide: relative paths in MkDir,
RmDir, and file opens all resolve against a working directory you do not control,
so anchor every path to ThisWorkbook.Path instead.
The honest verdict: one level, guarded, absolute
MkDir is the right tool for creating a folder — as long as you respect what it actually does. Four
rules:
- It makes one level → a nested path needs a level-by-level loop; neither
MkDirnorCreateFolderdoesmkdir -p. - It is not idempotent → guard with
If Dir(path, vbDirectory) = "" Then(orFolderExists) or it raiseserror 75on the second run. - A missing parent is
error 76→ build from the root down, not from the leaf. - A relative name follows
CurDir→ build absolute paths fromThisWorkbook.Pathso the folder always lands where you expect.
The moment you write MkDir twice in a script — once to create, once "just in case" — replace both
with the guarded loop. That single helper removes error 75, error 76, and the wrong-folder bug in
one move.
How ExcelMaster helps
Creating a folder safely means remembering that MkDir makes only one level, that it errors if
the parent is missing (76) or the folder already exists (75), and that a bare name follows
CurDir rather than your workbook — four traps around a statement that looks like it should just make a
folder.
ExcelMaster writes the create-folder
routine that will not stall. Describe the job — "save each report into a dated subfolder," or "build the
output tree if it isn't there" — and it produces the existence-guarded, level-by-level loop, anchored to
ThisWorkbook.Path, so the path is created once and never raises error 75 on a
re-run. You describe the folder you want; it writes the code that makes every missing level and skips
the rest.
Frequently asked questions
How do I create a folder in VBA?
Use the MkDir statement with a full path: MkDir "C:\Reports". It creates one folder level inside a
parent that must already exist. Guard it so it does not fail on a re-run —
If Dir("C:\Reports", vbDirectory) = "" Then MkDir "C:\Reports" — because MkDir raises error 75 if
the folder already exists rather than doing nothing.
Why does VBA MkDir give error 76 Path not found?
Because MkDir creates only one level and the parent folder in your path does not exist.
MkDir "C:\Reports\2026\Q1" fails with error 76 if C:\Reports\2026 is missing. MkDir does not
create intermediate folders, and neither does FileSystemObject.CreateFolder. To build a deep path,
create each level from the root down in a loop, checking Dir(level, vbDirectory) before each MkDir.
How do I create a folder only if it does not already exist?
Check first with the vbDirectory flag: If Dir("C:\Reports", vbDirectory) = "" Then MkDir "C:\Reports". Dir(path, vbDirectory) returns the folder name when it exists and an empty string when
it does not, so the MkDir runs only when the folder is absent. The clearer alternative is
fso.FolderExists(path) from the FileSystemObject, which reads unambiguously and does not disturb the
Dir cursor.
How do I create nested folders in one go in VBA?
There is no single mkdir -p call in built-in VBA — both MkDir and FileSystemObject.CreateFolder
create just one level. Split the path on "\" and create each level top-down: start from the drive,
append one segment at a time, and MkDir each segment that Dir(build, vbDirectory) reports as
missing. That loop creates Reports, then 2026, then Q1, skipping any that already exist.
Where does MkDir create a folder when I use a relative path?
A relative path such as MkDir "Reports" is resolved against CurDir, Excel's current working
directory — which is usually not your workbook's folder and can change when a File Open dialog
points elsewhere. To create the folder next to your workbook every time, build an absolute path:
MkDir ThisWorkbook.Path & "\Reports".
Tested in
Tested in: Excel 365 (Windows 11), VBA 7.1 — last verified 2026-08-23.
Related guides: VBA RmDir · VBA CurDir · VBA Check If File Exists · VBA Dir · VBA FileSystemObject
