assigning a marco from a control sheet

planetshwee

New Member
Joined
Oct 12, 2006
Messages
1
Hi, this is my first post so please bear with me if I don't give all the info required -

I am writing a control sheet that generates several reports (spreadsheets) from some source data (text file). I am nearly finished but am having one last problem -

The output reports have several levels of detail and I an have added three commandbuttons to the file, each will select a different criteria in a hidden autofilter at the end of the report (column O) thus select the different levels. I have written and exported three little macros to this effect and am then importing the module into each of the outputted reports, code as below -

Application.VBE.ActiveVBProject.VBComponents.Import "C:\EDD\MODULE1.bas

I did the following to create the buttons (x3 per worksheet) -

MyActualWorksheet.OLEObjects.Add ClassType:="Forms.CommandButton.1", Link:=False, DisplayAsIcon:=False, Left:=15.9, Top:=35.3, Width:=82.1, Height:=24.7
MyActualWorksheet.OLEObjects("CommandButton1").Object.Caption = "GL Detail"


What I can't figure out how to do is assign the filtering macro's to the buttons (the code needs to be written in the control file and not the spreadsheet with the buttons and it is this that is causing me problems). If it helps, "MyActualWorksheet" is one of the worksheets in the output reports.


Please help as Eddie is a confused little lad and a bit of a beginner in the world of code.... :confused:
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

IAVENOIDEAWHAIMDOIN

Active Member
Joined
Nov 12, 2004
Messages
291
Hi,

Let me get this straight... are you trying to create an event procedure (i.e. CommandButtonX_Click) in a workbook your macro has just created? If so you might find http://www.cpearson.com/excel/vbe.htm useful, particularly the part subtitled "Creating An Event Procedure".

It is important to note you will have to set reference to the "Microsoft Visual Basic For Applications Extensibility 5.3" library. There is an explanation near the top of the linked page on how to do this.
 

Forum statistics

Threads
1,141,679
Messages
5,707,786
Members
421,527
Latest member
Tamiwsw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top