Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
nx3 nx3 is offline
external usenet poster
 
Posts: 8
Default VBA assign macro to button from a different file (simple you'd

I'd tried ActiveWorkbook.Name actually, sorry not mentioned it. Same
difference as

Selection.OnAction = "file_01.xls!ModifyMenu"

This fails, runtime 1004. 'Unable to set the OnAction property of the button
class'

It seems to have a problem because the active code is in master but the
activesheet is in file_01. When you assign a macro to a object if the code is
in the same file then you don't reference the file. I'm referencing a button
and code in another file from master and that's what causes the problem.

If I create the button in any file other than the one I want it in I can
reference the correct code. Then cut and paste the button to the correct file
with correct link intact. e.g the code above....

"Bob Phillips" wrote:

How about this

With ActiveSheet.Buttons.Add(Range("A2:H2").Width, Range("I1:I2").Height,
Range("I2").Width, Range("I4").Top)
.Name = "ModifySheet"
.Caption = "Modify Worksheet"
.OnAction = ActiveWorkbook.Name & "!ModifyMenu"
End With


--

HTH

RP
(remove nothere from the email address if mailing direct)


"NX3" wrote in message
...
Thanks for replying Bob.

The code to draw the button and assign are as follows :

With ActiveSheet.Buttons.Add(Range("A2:H2").Width, Range("I1:I2").Height,
Range("I2").Width, Range("I4").Top)
.Name = "ModifySheet"
.Caption = "Modify Worksheet"
.OnAction = "ModifyMenu"
End With

The problem is that when I click the button its looking for 'ModifyMenu'

in
the master file not the activework book. To me this looks more or less the
same as the sample and various other postings I've read.

If the button is in the master file I can assign the other way e.g

Selection.OnAction = "'H810-26011006_Oct-05.xls'!ModifyMenu"

So a really dumb solution would be draw the button in file_01 etc cut and
paste it into master, use the line above which works, then cut and paste

it
back to file_01. This works but it seems a very silly way of doing it :-\

The question is, how from master can I draw a button and assign code in
file_01 ? As per my original examples they all link back to master which
doesn't have the code even.... I've been pulling my hair out on this one

to
say the least !!

TIA




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
Assign a macro to a button totofab Excel Discussion (Misc queries) 4 December 13th 07 06:16 PM
Button assign macro breaks with file name change and appears elsew Student Excel Discussion (Misc queries) 2 July 25th 06 09:06 PM
How do I Assign Macro to a button? BellExcel Charts and Charting in Excel 4 May 20th 05 07:21 PM
Assign macro to button Frank Kabel Excel Programming 0 May 24th 04 04:03 PM
Assign button to run macro jamie85[_5_] Excel Programming 8 February 3rd 04 01:44 PM


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

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

About Us

"It's about Microsoft Excel"