ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Hard code the workbook name in macro (https://www.excelbanter.com/excel-programming/429052-hard-code-workbook-name-macro.html)

Bruce

Hard code the workbook name in macro
 
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

Mike H

Hard code the workbook name in macro
 
Hi,

Try this with the name changed to your other workbook

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

Mike

"Bruce" wrote:

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


joel

Hard code the workbook name in macro
 
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

"Mike H" wrote:

Hi,

Try this with the name changed to your other workbook

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

Mike

"Bruce" wrote:

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



All times are GMT +1. The time now is 12:02 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com