Creating a button with macro on a different workbook - vba

I currently have a macro which creates another workbook and adds a button to it. I've assigned a macro to the button, but I believe I still need the master workbook to actually run the macro.
Is there a way to have the macro run on the new workbook without referring to the master workbook? In other words, is it possible to programmatically add a button to a new workbook with a macro and have it be independent of the original workbook?
Thanks in advance!

I'd go like this:
have your "master" workbook with a template worksheet whit both an ActiveX button and its corresponding code in its code pane
say its name is "TemplateSheetWithButtonAndCode"
in your macro use
Worksheets("TemplateSheetWithButtonAndCode").Copy
ActiveWorkbook.SaveAs "c:\MyFolder\MyWorkbooK"
this will generate a new workbook with a copy of your "template" worksheet as its only worksheet, along with necessary code to have the button work

Place the button on a template worksheet. Place the button's associated macro in that worksheet's code area.
If you export the worksheet to another workbook, you will also be exporting the button and the macro.

Related

VBA Userform read another workbook dynamically without opening it

I'm fairly new to VBA. I'm trying to create a user form where the user can select another workbook as read only and copy some of the data to the current workbook. I don't want the other workbook to open.
I found this https://www.encodedna.com/excel/copy-data-from-closed-excel-workbook-without-opening.htm but the excel document is hard coded. Is it possible to select a workbook dynamically, through a file dialog without that workbook popping up?
Thank you

How to generate new workbooks with vba button intact

I have a worksheet that has a macro (as a button) that generates a separate worksheet w/ some analysis on it. Is it possible to generate a new workbook with the old workbook's VBA intact and with the new workbook's button referring to the new workbook's VBA?

Fire macro in Personal.xlsb on ANY workbook open

I am attempting to place a macro in Personal.xlsb that will fire whenever any workbook is opened. I have searched multple sites for an answer and all relate to Auto_Open or WorkBook_Open which have to be in a macro running in the workbook being opened. Is there a way to see these events from another workbook?

Copy a worksheet to a new workbook and have a button point to the macro in the NEW workbook?

I have a worksheet that looks like a form. It has a "Reset" button to clear the values.
There is a macro that I can run that copies that sheet into a new Workbook and emails it to someone. The module that contains the macros gets copied into it and all is almost ok. The problem is, the button on the worksheet that runs the reset macro still points back to the original document. How can I have it point to the macro within itself?
Edit: One thing to point out is that I do have macros within that sheet that fire off if cells are changed. Those work great and don't try and load the original file. It's just the ones within the button that don't work.
You should use 'ActiveX form button' instead of 'simple form button' (which I guess you use). Then you have to put reset procedure within ActiveX button event (double click on it to edit that procedure). As the result of coping the sheet both button and the procedure would be moved to new workbook which will break any reference to original file.

Triggering external macro on button click from normal excel workbook (.xlsx)

Stated simply my question is as follows Is it possible for a button on a worksheet in a normal excel workbook (.xlsx not .xlsm) to trigger a macro in another file specifically an installed excel add in (.xlam).
Here is some background on why I want to achieve this. I have a workbook that many users need to be able to view but only some need to be able to update by filling in a form on another sheet and calling a macro in an add in. The worksheet should not contain any macros to avoid security warnings when opened by normal users. I can do this by having a ribbon button in the add in that the user clicks which will then check that the correct workbook is open and that the form is filled in etc. before executing the update code. However the interface would be nicer if the button instead of appearing on the ribbon was on the worksheet just below the form. Therefore my question is it possible to trigger an external macro from a button click in a non macro enabled workbook.
Yes, you can assign an external macro (which should be .xlsm file) to a non-macro-enabled workbook (.xlsx) button. My xlsm macro resides in the same directory as the xlsx workbook for simplicity. (Note: I am using Excel 2010)
Firstly, you must open your xlsm macro in the same instance of Excel window (i.e. do not open a new instance of Excel) so that your xlsx workbook will be able to see/access it.
Right-click on your xlsx workbook button and select "Assign Macro..."
Make sure you select Macros in: All Open Workbooks
All macros in open workbooks will be shown (this is why it is important to do step 1).
Select the desired macro from the list then click OK.
I don't see how you can execute a macro from a control in a non-macro-enabled workbook.