Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 138
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
hard code a password in a vba code Dan Excel Programming 2 April 22nd 09 04:44 AM
How do I call up a line of code that references a cell/range in theactive workbook workbook where I am running my macro from? Lav Excel Programming 2 November 11th 08 05:04 PM
Not Hard Code If FIRSTROUNDKO via OfficeKB.com Excel Discussion (Misc queries) 3 July 10th 07 04:11 PM
Hard Code DLL Reference in VBA alex Excel Programming 4 June 10th 04 05:05 PM
Hard Code DLL Reference in VBA alex Excel Programming 0 June 10th 04 01:20 PM


All times are GMT +1. The time now is 07:33 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"