create macro run button when VBA codes on "This Workbook"

User avatar
PRADEEPB270
3StarLounger
Posts: 354
Joined: 27 Oct 2013, 15:11
Location: Gurgaon INDIA

create macro run button when VBA codes on "This Workbook"

Post by PRADEEPB270 »

Please refer my attach file.

In this file,there are 3 macros.One is exist on 'Sheet1(BOM)' and other 2 are exist on 'Thisworkbook'.

My problem is ,I can create the Macro run button only the vba codes exist on 'Sheet1(BOM)' and unable to create the other 2 macro run button which are exist on 'Thisworkbook'.Only one macro run button is working and other 2 are not working i.e.Countsheets and BOMdownloading.

Can it be possible to create all macro run buttons on a 'BOM'sheet whether it is on 'Sheet1' or 'Thisworkbook' ( Attach my file )?

Please attach a sample file for better understanding and steps that how to create?
Regards

Pradeep Kumar Gupta
INDIA

User avatar
HansV
Administrator
Posts: 78531
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: create macro run button when VBA codes on "This Workbook

Post by HansV »

The two command buttons on the BOM sheet are ActiveX buttons. The On Click event procedures for these buttons MUST be in the code module of the BOM sheet, otherwise they won't work.

The code for CommandButton1 is already in the correct place.

You must cut the CommandButton2_Click procedure from ThisWorkbook and paste it into the code module of the BOM sheet, above or below the code for CommandButton1.

The ThisWorkbook module is only intended for workbook events such as Workbook_Open. It is NOT intended for general macros. General macros must be placed in a standard module. So create a standard module using Insert | Module, then cut the BOMDOWNLOADCORRECTION macro from ThisWorkbook and paste it into the new standard module.
Best wishes,
Hans

User avatar
PRADEEPB270
3StarLounger
Posts: 354
Joined: 27 Oct 2013, 15:11
Location: Gurgaon INDIA

Re: create macro run button when VBA codes on "This Workbook

Post by PRADEEPB270 »

Thanks for the valuable sharing informations.It will update my more and more learning.
Regards

Pradeep Kumar Gupta
INDIA