View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default VBA assign macro to button from a different file (simple you'd thi



--

HTH

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


"NX3" wrote in message
...
I have to modify 2000 files so I've written a master file that loops

through
a list, importing modules and forms into the 2000 files it opens and

closes.
On each file when open it draws a button on worksheet. I then want to

assign
a macro to the button called "ModifyMenu" . The code for 'Modifymenu' is
imported into file_01.xls and is a unique name. It does not exist is
master.xls, so no confusion.

The code for assigning the code is as follows :

Windows("file_01.xls").Activate
ActiveSheet.Shapes("Button").Select
or
Workbooks("file_01.xls").Sheets("1 B").Shapes("Button").Select


Then

Selection.OnAction = "ModifyMenu"
(This links to master.xls!ModifyMenu not file_01.xls)

Selection.OnAction = "file_01.xls!ModifyMenu"
(This fails, runtime 1004. 'Unable to set the OnAction property of the
button class)

Selection.OnAction = ThisWorkbook.Name & "!ModifyMenu"
(This links to master. MAster is the active code even though 'file_01.xls'
is the active worksheet)

Variations on the above seem to result in the same 1004 error or linking
back to master regardless of the fact I'm trying to link to file_01.xls.

Any help much appricated.
Regards
Nick