Hard code the workbook name in macro

B

Bruce

I have a macro to delete a worksheet.
When its run multiple excel files are open. To be sure it doens't accidently
delete the sheet from the wrong file, how can I hardcode the workbook name
into my macro. Assume my workbook is called myFile.xls

Bruce

Sub DelSheets()
Sheets("Sheet2").Delete
End Sub
 
M

Mike H

Hi,

Try this with the name changed to your other workbook

Workbooks("Otherbook.xls").Sheets("Sheet2").Delete

Mike
 
J

Joel

When you open the workbook set an object to the workbook

set bk = workbooks.open(filename:=book1.xls)

set sourceSht = bk.sheets("sheet1")
MyName = Sourcesht.Range("A1")

bk.close savechanges:=false
 

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

Top