PC Review


Reply
Thread Tools Rate Thread

Assigning macro buttons to macro code in another file

 
 
Enz
Guest
Posts: n/a
 
      25th May 2009
Hello

Does anyone know if you can do the following?

I coded a macro that creates several tabs within it (call it
Executive), each of which contains a button to invoke a macro (and
each sheet has its' own macro code). Then I create an output file
that copies the desired tabs from Executive to a new Workbook output
file. I am currently coding the portion of the Executive macro where
I am re-assigning the existing button in each tab to point to the
macro code within the output file sheets, that I am attempting to
create. The output file will be run independently from the
originating Executive macro file, so I need the output file to
reference only macro code within itself.

When I attempt to specify the output file name when assigning the
button to execute the macro code within the new Workbook output macro
file, I get a run time error '1004' 'Unable to set the OnAction
property of the Button Class'. I believe I am getting this message
because the button class does not allow you to specify another file
reference when assigning macro code to buttons outside the current
macro executing. Can anyone confirm my belief? Or perhaps I have an
error I am not yet seeing.

This is the logic that attempts to re-assign the macro code to
reference the logic in the output file

'Note that this index is referencing the Executive workbook but will
be the same number in the output workbook
'Note "Desk Output" is the new workbook that contains the subroutine
CopyLogs in each worksheet tab

lcurrentDate = Format(Date, " yyyy mmm d")
lindex = ThisWorkbook.Sheets(ActiveSheet.Name).Index
ActiveSheet.Shapes("Button 3").Select
Selection.OnAction = "Desk Output " & lcurrentDate & "!Sheet" & lindex
& ".CopyLogs"

I have validated all the variables and I believe I have the correct
values as it stands if this were to work.

Any thoughts would be greatly appreciated.

Regards,
Enz
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      25th May 2009
How about an alternative that will make life lots easier?

Instead of using buttons from the forms toolbar and assigning macros to them,
how about using commandbuttons from the Control Toolbox toolbar.

Since your code is in the sheet module anyway, there wouldn't be much of a
change (since the code will travel with the copied worksheet when it's placed
into the new workbook).

But it will require some changes.



Enz wrote:
>
> Hello
>
> Does anyone know if you can do the following?
>
> I coded a macro that creates several tabs within it (call it
> Executive), each of which contains a button to invoke a macro (and
> each sheet has its' own macro code). Then I create an output file
> that copies the desired tabs from Executive to a new Workbook output
> file. I am currently coding the portion of the Executive macro where
> I am re-assigning the existing button in each tab to point to the
> macro code within the output file sheets, that I am attempting to
> create. The output file will be run independently from the
> originating Executive macro file, so I need the output file to
> reference only macro code within itself.
>
> When I attempt to specify the output file name when assigning the
> button to execute the macro code within the new Workbook output macro
> file, I get a run time error '1004' 'Unable to set the OnAction
> property of the Button Class'. I believe I am getting this message
> because the button class does not allow you to specify another file
> reference when assigning macro code to buttons outside the current
> macro executing. Can anyone confirm my belief? Or perhaps I have an
> error I am not yet seeing.
>
> This is the logic that attempts to re-assign the macro code to
> reference the logic in the output file
>
> 'Note that this index is referencing the Executive workbook but will
> be the same number in the output workbook
> 'Note "Desk Output" is the new workbook that contains the subroutine
> CopyLogs in each worksheet tab
>
> lcurrentDate = Format(Date, " yyyy mmm d")
> lindex = ThisWorkbook.Sheets(ActiveSheet.Name).Index
> ActiveSheet.Shapes("Button 3").Select
> Selection.OnAction = "Desk Output " & lcurrentDate & "!Sheet" & lindex
> & ".CopyLogs"
>
> I have validated all the variables and I believe I have the correct
> values as it stands if this were to work.
>
> Any thoughts would be greatly appreciated.
>
> Regards,
> Enz


--

Dave Peterson
 
Reply With Quote
 
Enz
Guest
Posts: n/a
 
      25th May 2009
Thanks Dave for your suggestion. I made the changes you suggested and
it worked perfectly the first time. Much appreciated.

regards,
Enzo

On May 25, 1:13*pm, Dave Peterson <peter...@verizonXSPAM.net> wrote:
> How about an alternative that will make life lots easier?
>
> Instead of using buttons from the forms toolbar and assigning macros to them,
> how about using commandbuttons from the Control Toolbox toolbar.
>
> Since your code is in the sheet module anyway, there wouldn't be much of a
> change (since the code will travel with the copied worksheet when it's placed
> into the new workbook).
>
> But it will require some changes.
>
>
>
>
>
> Enz wrote:
>
> > Hello

>
> > Does anyone know if you can do the following?

>
> > I coded a macro that creates several tabs within it (call it
> > Executive), each of which contains a button to invoke a macro (and
> > each sheet has its' own macro code). *Then I create an output file
> > that copies the desired tabs from Executive to a new Workbook output
> > file. *I am currently coding the portion of the Executive macro where
> > I am re-assigning the existing button in each tab to point to the
> > macro code within the output file sheets, that I am attempting to
> > create. *The output file will be run independently from the
> > originating Executive macro file, so I need the output file to
> > reference only macro code within itself.

>
> > When I attempt to specify the output file name when assigning the
> > button to execute the macro code within the new Workbook output macro
> > file, I get a run time error '1004' *'Unable to set the OnAction
> > property of the Button Class'. *I believe I am getting this message
> > because the button class does not allow you to specify another file
> > reference when assigning macro code to buttons outside the current
> > macro executing. *Can anyone confirm my belief? *Or perhaps I have an
> > error I am not yet seeing.

>
> > This is the logic that attempts to re-assign the macro code to
> > reference the logic in the output file

>
> > 'Note that this index is referencing the Executive workbook but will
> > be the same number in the output workbook
> > 'Note "Desk Output" is the new workbook that contains the subroutine
> > CopyLogs in each worksheet tab

>
> > lcurrentDate = Format(Date, " yyyy mmm d")
> > lindex = ThisWorkbook.Sheets(ActiveSheet.Name).Index
> > ActiveSheet.Shapes("Button 3").Select
> > Selection.OnAction = "Desk Output " & lcurrentDate & "!Sheet" & lindex
> > & ".CopyLogs"

>
> > I have validated all the variables and I believe I have the correct
> > values as it stands if this were to work.

>
> > Any thoughts would be greatly appreciated.

>
> > Regards,
> > * Enz

>
> --
>
> Dave Peterson- Hide quoted text -
>
> - Show quoted text -


 
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
in vb, what is the 1-line code of assigning a macro using click =?Utf-8?B?RXhjZWxTdXBlclVzZXI=?= Microsoft Excel Programming 3 26th Sep 2007 06:52 PM
Can I use code/macro to change code/macro in an existing file? =?Utf-8?B?U2NvdHQgQmVkb3dz?= Microsoft Excel Programming 2 14th Feb 2007 05:50 AM
Re: Assigning Macro by using code Bob Phillips Microsoft Excel Programming 1 9th Jan 2007 07:31 PM
Assigning a Macro to a Shockwave File Chris Hankin Microsoft Excel Programming 2 23rd Jun 2004 09:51 AM
Assigning Macro's to control buttons. catdataman Microsoft Excel Programming 3 23rd Dec 2003 05:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:01 PM.