dpaton05
Well-known Member
- Joined
- Aug 14, 2018
- Messages
- 2,352
- Office Version
- 365
- 2016
- Platform
- Windows
I tried to copy code off the net and modify it but it didn't work. I am trying to see if a folder and file exists and if not, create it.
This is what I wrote.
It needs to look for List.xlsm in a folder called "Young People" in the current directory and if it doesn't exist, create it.
Can someone help me with the above code as it doesn't work please?
This is what I wrote.
VBA Code:
Sub TestSheetCreate()
Dim newSheetName As String
Dim checkSheetName As String
newSheetName = ThisWorkbook.Path & "\Young People\list.xlsm"
On Error Resume Next
checkSheetName = Worksheets(newSheetName).Name
If checkSheetName = "" Then
Worksheets.Add.SaveAs = newSheetName
MsgBox "The sheet named ''" & newSheetName & _
"'' does not exist in this workbook but it has been created now.", _
vbInformation
Else
MsgBox "The sheet named ''" & newSheetName & _
"''exist in this workbook.", vbInformation
End If
End Sub
It needs to look for List.xlsm in a folder called "Young People" in the current directory and if it doesn't exist, create it.
Can someone help me with the above code as it doesn't work please?