A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Looking at the code it seems probable that the process cannot create the path and there are some other issues also. Try the following instead, which does work:
Option Explicit
Sub MakeFolders()
Dim strDir As String
Dim lstRow As Long
Dim i As Long
Dim xlBook As Workbook
Dim xlSheet As Worksheet
Const strName As String = "Customer Outgoing Email List"
Set xlBook = ActiveWorkbook
Set xlSheet = xlBook.Worksheets(strName)
lstRow = xlSheet.Cells(xlSheet.Rows.Count, "A").End(xlUp).Row
Application.ScreenUpdating = False
For i = 1 To lstRow 'I guess no header row?
'change the path on the next line where you want to create the folders
strDir = "H:\My Documents\customers for Jan 2017" & _
Left(Range("A" & i).Value, InStrRev(Range("A" & i).Value, "@") - 1)
If CreateFolders(strDir) = False Then GoTo lbl_exit
DoEvents
Next
Application.ScreenUpdating = True
lbl_exit:
Set xlBook = Nothing
Set xlSheet = Nothing
Exit Sub
End Sub
Private Function CreateFolders(strPath As String) As Boolean
'A Graham Mayor/Greg Maxey AddIn Utility Macro
'This will create the full path (if missing) but will create an error message and stop processing
'if the drive letter does not exist, or the path contains illegal characters.
Dim oFSO As Object
Dim lngPathSep As Long
Dim lngPS As Long
On Error GoTo err_Handler
If Right(strPath, 1) <> "" Then strPath = strPath & ""
lngPathSep = InStr(3, strPath, "")
If lngPathSep = 0 Then GoTo lbl_exit
Set oFSO = CreateObject("Scripting.FileSystemObject")
Do
lngPS = lngPathSep
lngPathSep = InStr(lngPS + 1, strPath, "")
If lngPathSep = 0 Then Exit Do
If Len(Dir(Left(strPath, lngPathSep), vbDirectory)) = 0 Then Exit Do
Loop
Do Until lngPathSep = 0
If Not oFSO.FolderExists(Left(strPath, lngPathSep)) Then
oFSO.CreateFolder Left(strPath, lngPathSep)
End If
lngPS = lngPathSep
lngPathSep = InStr(lngPS + 1, strPath, "")
Loop
CreateFolders = True
lbl_exit:
Set oFSO = Nothing
Exit Function
err_Handler:
MsgBox "Unable to create " & vbCr & strPath & vbCr & vbCr & _
"Error Number: " & Err.Number & vbCr & Err.Description
Err.Clear
GoTo lbl_exit
End Function