Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Macro Name problem when I change workbook 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Macro Name problem when I change workbook name?

See answer to previous posting.

--
Regards,
Tom Ogilvy

"Mike" wrote in message
oups.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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Macro Name problem when I change workbook name?

Tom,

My Macro doesn't have a code! My macro just performs few operations
using Tools, Macro, Record New Macro...etc.

I opened ABC.xls file and saved it as, using saveas, as DEF.xls

Next, I pushed the button that my macro is linked to but gave me again
an error "out of range" and the file closed!
HOW can I prevent this?

Thanks,
Mike

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Macro Name problem when I change workbook name?

In case you can't see your other post, Jake Marx posted this and I think it
is probably what you want:

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

"Mike" wrote in message
oups.com...
Tom,

My Macro doesn't have a code! My macro just performs few operations
using Tools, Macro, Record New Macro...etc.

I opened ABC.xls file and saved it as, using saveas, as DEF.xls

Next, I pushed the button that my macro is linked to but gave me again
an error "out of range" and the file closed!
HOW can I prevent this?

Thanks,
Mike



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
Macro change problem Dr Hackenbush Excel Discussion (Misc queries) 3 February 6th 10 04:54 PM
Macro broken with workbook name change Annabelle Excel Discussion (Misc queries) 2 February 3rd 06 12:48 AM
Macro to change worksheets in the same workbook James C Excel Discussion (Misc queries) 2 October 19th 05 08:04 PM
Problem closing a workbook using a macro Steve Excel Programming 3 September 21st 04 01:03 PM
A Macro to change macros? VBA problem MrMerton Excel Programming 2 July 6th 04 02:06 PM


All times are GMT +1. The time now is 09:53 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"