Deleting sheet2 and sheet3 in a workbook

C

CAM

What is the code to delete sheet2 and sheet3 in a close workbook from a
folder call C:\Budget I do want to keep sheet1 only.

Thank you in advance.

Regards,
 
P

Patrick Molloy

your code will need to open that workbook

dim wb as workbook
dim sh as worksheet
set wb = workbooks.open("{full name and path}")

for each sh in wb.worksheets
if ws.name<>"Sheet1" then
Application.DisplayAlerts = False
ws.delete
Application.DisplayAlerts = True
end if
next
wb.close TRUE
 
C

CAM

Thanks Patrick for the tip

Regards

Patrick Molloy said:
your code will need to open that workbook

dim wb as workbook
dim sh as worksheet
set wb = workbooks.open("{full name and path}")

for each sh in wb.worksheets
if ws.name<>"Sheet1" then
Application.DisplayAlerts = False
ws.delete
Application.DisplayAlerts = True
end if
next
wb.close TRUE
 
Top