Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Changing Macro Name?

Hi everyone,

Say I created a macro I named "Base" in a an excel workbook named
ABC.xls

Later, say I changed the file name to DEF.xls

Now, when I click on the macro button to execute, I get "out of range"
error and the file close!

How can I make the macro name is independent of the file name; so it
doesn't keep referring to the old file name?

Regards,
Mike

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Changing Macro Name?

You can't. The macro is contained in the file, so it is part of the
identification.

If you want to rename the file, open it in excel and rename it by doing a
file saveas.

--
Regards,
Tom Ogilvy

"Mike" wrote in message
ups.com...
Hi everyone,

Say I created a macro I named "Base" in a an excel workbook named
ABC.xls

Later, say I changed the file name to DEF.xls

Now, when I click on the macro button to execute, I get "out of range"
error and the file close!

How can I make the macro name is independent of the file name; so it
doesn't keep referring to the old file name?

Regards,
Mike



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Changing Macro Name?

Mike,

Does your code look like this?

Workbooks("ABC.xls").Sheets("Sheet1").Range("A1"). Value=1

If so, change it to:

ThisWorkbook.Sheets("Sheet1").Range("A1").Value=1

ThisWorkbook will always return a reference to the workbook in which the VBA
code resides, so you don't have to worry about name changes.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


Mike wrote:
Hi everyone,

Say I created a macro I named "Base" in a an excel workbook named
ABC.xls

Later, say I changed the file name to DEF.xls

Now, when I click on the macro button to execute, I get "out of range"
error and the file close!

How can I make the macro name is independent of the file name; so it
doesn't keep referring to the old file name?

Regards,
Mike


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Changing Macro Name?

Jake read your post differently from me - and after rereading your post,
perhaps he is correct.

I saw button and thought you had assigned the macro to a command button or
other type of button.

So my comments would only be appropriate in that context.

--
Regards,
Tom Ogilvy

"Tom Ogilvy" wrote in message
...
You can't. The macro is contained in the file, so it is part of the
identification.

If you want to rename the file, open it in excel and rename it by doing a
file saveas.

--
Regards,
Tom Ogilvy

"Mike" wrote in message
ups.com...
Hi everyone,

Say I created a macro I named "Base" in a an excel workbook named
ABC.xls

Later, say I changed the file name to DEF.xls

Now, when I click on the macro button to execute, I get "out of range"
error and the file close!

How can I make the macro name is independent of the file name; so it
doesn't keep referring to the old file name?

Regards,
Mike





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Changing Macro Name?

Hi Tom,

Tom Ogilvy wrote:
Jake read your post differently from me - and after rereading your
post, perhaps he is correct.

I saw button and thought you had assigned the macro to a command
button or other type of button.


Hmmm....after reading this post and rereading the OP's post, I think you may
be the one who interpreted the question correctly. <g

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]

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
Why is my macro changing sum to count? punter Excel Discussion (Misc queries) 2 June 21st 06 09:51 PM
Help with changing a Macro Mike Rogers Excel Discussion (Misc queries) 1 March 26th 06 11:51 PM
Help with changing a Macro Mike Rogers Excel Discussion (Misc queries) 0 March 26th 06 11:43 PM
Macro Ran in Excel 97 but in XP. What Needs Changing JB[_2_] Excel Programming 1 February 12th 04 08:46 PM
Macro for changing tabs Chip Pearson Excel Programming 5 February 12th 04 08:17 PM


All times are GMT +1. The time now is 02:58 PM.

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"