Check if a spreadsheet exists and if not, create it

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,343
Office Version
  1. 365
  2. 2016
Platform
  1. 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.
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?
 

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
20,532
Office Version
  1. 2016
  2. 2013
  3. 2007
Platform
  1. Windows
Patience Dave......
without seeing the other codes, try
VBA Code:
Set f = wbList.shList.Range("A:A").Find(newyp, xlValues, xlWhole)
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,343
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Thanks Michael, what other Code do you need to see?
 

Forum statistics

Threads
1,136,321
Messages
5,675,063
Members
419,548
Latest member
wfarzand

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
Top