I have an Excel VBA macro that creates a folder tree based on an excel file.
My current issue is that I seem to get an error every time the absolute directory gets very long.
The program will throw run time error 76 (path not found). I have a feeling that this is because the script references an absolute path that exceeds 256 characters.
Is there any work-around for this? Or is my only option to shorten the folder names and thus the absolute path string?
EDIT
The code I’m using is the following:
Dim asheet As Range, r As Range, c As Range
Dim fPath As String, tmp As String
Set asheet = ActiveSheet.UsedRange
For Each r In asheet.Rows
fPath = DEST_FOLDER
For Each c In r.Cells
tmp = Trim(c.Value)
If Len(tmp) = 0 Then
Exit For
Else
tmp = Clean(tmp)
fPath = fPath & tmp & "\"
If Len(Dir(fPath, vbDirectory)) = 0 Then MkDir fPath
End If
Next c
Next r
Clean() is a self-defined function that will simply remove special characters from the string, i.e. !, #, _, @, $, &, *, ^, and %.
Is there another method I could use to create these folders that perhaps would use a relative path instead of an absolute one?
The windows API has a limit of 260 characters (C:\ + 256 characters + ) in some circumstances. If you refer to your previous question, have you tried using
SHFileOperationWinstead ofSHFileOperationA?