Deleting sheet2 and sheet3 in a workbook

  • Thread starter Thread starter CAM
  • Start date Start date
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,
 
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top