PC Review


Reply
Thread Tools Rate Thread

Assigned macro change

 
 
Otto Moehrbach
Guest
Posts: n/a
 
      22nd Nov 2008
Excel XP & Win XP
Everything below is done via VBA.
I have a workbook, say A.xls, that has a number of macros and a number of
buttons here and there to trigger the macros. All the macros assigned to
the buttons are in that workbook.
I do some work with this workbook.
Then I SaveAs as B.xls.
In the B.xls workbook, the macro assignments all reference A.xls as the
location of the macros.
I want the macro assignments in B.xls to reference B.xls.
Is there some code that I can employ at the time of the SaveAs to carry the
macro assignments to the new workbook?
If not, what would be the best way to change the macro assignments to B.xls
after B.xls is created?
Thanks for your time. Otto


 
Reply With Quote
 
 
 
 
Gary Keramidas
Guest
Posts: n/a
 
      22nd Nov 2008
do you have hard coded references to A.xls?

if so, change them to thisworkbook.

don't know without seeing an example of the code that's in question.

--


Gary

"Otto Moehrbach" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Excel XP & Win XP
> Everything below is done via VBA.
> I have a workbook, say A.xls, that has a number of macros and a number of
> buttons here and there to trigger the macros. All the macros assigned to the
> buttons are in that workbook.
> I do some work with this workbook.
> Then I SaveAs as B.xls.
> In the B.xls workbook, the macro assignments all reference A.xls as the
> location of the macros.
> I want the macro assignments in B.xls to reference B.xls.
> Is there some code that I can employ at the time of the SaveAs to carry the
> macro assignments to the new workbook?
> If not, what would be the best way to change the macro assignments to B.xls
> after B.xls is created?
> Thanks for your time. Otto
>



 
Reply With Quote
 
Otto Moehrbach
Guest
Posts: n/a
 
      22nd Nov 2008
Gary
Thanks for your help. In the A.xls WB the button assignment is simply
"MacroName". In the B.xls WB the assignment is "A.xls!MacroName". I want
the assignment to be simply MacroName in both workbooks so that any button
clicked on will run a macro that is in the WB that holds that button.
Thanks again. Otto
"Gary Keramidas" <GKeramidasAtMsn.com> wrote in message
news:(E-Mail Removed)...
> do you have hard coded references to A.xls?
>
> if so, change them to thisworkbook.
>
> don't know without seeing an example of the code that's in question.
>
> --
>
>
> Gary
>
> "Otto Moehrbach" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> Excel XP & Win XP
>> Everything below is done via VBA.
>> I have a workbook, say A.xls, that has a number of macros and a number of
>> buttons here and there to trigger the macros. All the macros assigned to
>> the buttons are in that workbook.
>> I do some work with this workbook.
>> Then I SaveAs as B.xls.
>> In the B.xls workbook, the macro assignments all reference A.xls as the
>> location of the macros.
>> I want the macro assignments in B.xls to reference B.xls.
>> Is there some code that I can employ at the time of the SaveAs to carry
>> the macro assignments to the new workbook?
>> If not, what would be the best way to change the macro assignments to
>> B.xls after B.xls is created?
>> Thanks for your time. Otto
>>

>
>



 
Reply With Quote
 
Otto Moehrbach
Guest
Posts: n/a
 
      22nd Nov 2008
Joel
I wasn't clear. I have a workbook A.xls with macros and buttons to
execute the macros. With VBA I do a SaveAs and name it B.xls. A.xls is now
closed. I click a button in B.xls. I get an error because VBA is looking
for A.xls!MacroName. I want the macro that is assigned to a button in B.xls
to be a macro that is in WB B.xls. Otto
"Joel" <(E-Mail Removed)> wrote in message
news:27C3FBDE-4BEE-4C09-8FAD-(E-Mail Removed)...
> To reference the workbook with the macro make the following change
>
> from
> workbooks("A.xls")
>
> to
> ThisWorkbook
>
> "Otto Moehrbach" wrote:
>
>> Excel XP & Win XP
>> Everything below is done via VBA.
>> I have a workbook, say A.xls, that has a number of macros and a number of
>> buttons here and there to trigger the macros. All the macros assigned to
>> the buttons are in that workbook.
>> I do some work with this workbook.
>> Then I SaveAs as B.xls.
>> In the B.xls workbook, the macro assignments all reference A.xls as the
>> location of the macros.
>> I want the macro assignments in B.xls to reference B.xls.
>> Is there some code that I can employ at the time of the SaveAs to carry
>> the
>> macro assignments to the new workbook?
>> If not, what would be the best way to change the macro assignments to
>> B.xls
>> after B.xls is created?
>> Thanks for your time. Otto
>>
>>
>>



 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      22nd Nov 2008
You could loop through all the buttons/objects on the sheet and look at the
..onaction string. Then change the oldname.xls to the newname.xls
(thisworkbook.name???).

But if you're only using buttons from the Forms toolbar, you may find it much
easier to replace them with the Commandbuttons from the control toolbox toolbar.

Those objects don't have macros assigned to them. They have events and those
event procedures live under the worksheets that own the commandbuttons.



Otto Moehrbach wrote:
>
> Excel XP & Win XP
> Everything below is done via VBA.
> I have a workbook, say A.xls, that has a number of macros and a number of
> buttons here and there to trigger the macros. All the macros assigned to
> the buttons are in that workbook.
> I do some work with this workbook.
> Then I SaveAs as B.xls.
> In the B.xls workbook, the macro assignments all reference A.xls as the
> location of the macros.
> I want the macro assignments in B.xls to reference B.xls.
> Is there some code that I can employ at the time of the SaveAs to carry the
> macro assignments to the new workbook?
> If not, what would be the best way to change the macro assignments to B.xls
> after B.xls is created?
> Thanks for your time. Otto


--

Dave Peterson
 
Reply With Quote
 
Otto Moehrbach
Guest
Posts: n/a
 
      24th Nov 2008
Thanks Dave. That sounds like a good idea. Otto
"Dave Peterson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> You could loop through all the buttons/objects on the sheet and look at
> the
> .onaction string. Then change the oldname.xls to the newname.xls
> (thisworkbook.name???).
>
> But if you're only using buttons from the Forms toolbar, you may find it
> much
> easier to replace them with the Commandbuttons from the control toolbox
> toolbar.
>
> Those objects don't have macros assigned to them. They have events and
> those
> event procedures live under the worksheets that own the commandbuttons.
>
>
>
> Otto Moehrbach wrote:
>>
>> Excel XP & Win XP
>> Everything below is done via VBA.
>> I have a workbook, say A.xls, that has a number of macros and a number of
>> buttons here and there to trigger the macros. All the macros assigned to
>> the buttons are in that workbook.
>> I do some work with this workbook.
>> Then I SaveAs as B.xls.
>> In the B.xls workbook, the macro assignments all reference A.xls as the
>> location of the macros.
>> I want the macro assignments in B.xls to reference B.xls.
>> Is there some code that I can employ at the time of the SaveAs to carry
>> the
>> macro assignments to the new workbook?
>> If not, what would be the best way to change the macro assignments to
>> B.xls
>> after B.xls is created?
>> Thanks for your time. Otto

>
> --
>
> Dave Peterson



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Use Macro To Change Which Macro Assigned To Command Button CVinje Microsoft Excel Misc 0 25th May 2010 09:55 PM
Assigned Macro with argument? Ryder S Microsoft Excel Programming 3 31st Jul 2009 12:08 AM
Why can't I run an assigned macro? =?Utf-8?B?RG9veG8=?= Microsoft Excel Programming 0 11th Sep 2007 03:44 PM
Can't change macro assigned to drawing object =?Utf-8?B?TWFycXVpc0I=?= Microsoft Excel Programming 5 3rd Feb 2007 03:23 PM
Macro Assigned to a Button =?Utf-8?B?emVwaHly?= Microsoft Excel Misc 1 25th Oct 2006 03:33 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:56 PM.