ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Moving Macros with Sheets to New Workbook (https://www.excelbanter.com/excel-programming/321068-moving-macros-sheets-new-workbook.html)

Brad

Moving Macros with Sheets to New Workbook
 
Thanks for taking the time to read my question.

I have a workbook that has a lot of sheets in it. I'd like to be able to
make a copy of a sheet and place it in a new workbook, then e-mail the new
workbook. I want to send just the one sheet becuase each sheet is for a
different customer, and the information is sensitive.

My problem is... I have macros on each sheet. When I copy a sheet into a
new workbook, the macro comes with it, but the button on the sheet still
points to the macro in the original workbook. You have to right mouse click
"Assign Macro" and choose the macro in the current workbook. I don't want
the clients to have to do this.

Is there a property setting that tells Excel to use the macro in the new
workbook instead of the old workbook.

Thanks again for the help.

Brad



Brad

Moving Macros with Sheets to New Workbook
 
The answer is:

Create a button using the Control Toolbox instead of the Forms toolbar.

Doing this will embed the code to the button, not the workbook, and the
macro will move with the sheet.

Brad

"Brad" wrote:

Thanks for taking the time to read my question.

I have a workbook that has a lot of sheets in it. I'd like to be able to
make a copy of a sheet and place it in a new workbook, then e-mail the new
workbook. I want to send just the one sheet becuase each sheet is for a
different customer, and the information is sensitive.

My problem is... I have macros on each sheet. When I copy a sheet into a
new workbook, the macro comes with it, but the button on the sheet still
points to the macro in the original workbook. You have to right mouse click
"Assign Macro" and choose the macro in the current workbook. I don't want
the clients to have to do this.

Is there a property setting that tells Excel to use the macro in the new
workbook instead of the old workbook.

Thanks again for the help.

Brad



Tom Ogilvy

Moving Macros with Sheets to New Workbook
 
A workaround might be
activesheet.copy
for each btn in activesheet.buttons
btn.OnAction = application.Substitute(btn.OnAction, _
oldfilename,newfilename)
Next

Is the code for the buttons in the sheet module?



--
Regards,
Tom Ogilvy

"Brad" wrote in message
...
Thanks for taking the time to read my question.

I have a workbook that has a lot of sheets in it. I'd like to be able to
make a copy of a sheet and place it in a new workbook, then e-mail the new
workbook. I want to send just the one sheet becuase each sheet is for a
different customer, and the information is sensitive.

My problem is... I have macros on each sheet. When I copy a sheet into a
new workbook, the macro comes with it, but the button on the sheet still
points to the macro in the original workbook. You have to right mouse

click
"Assign Macro" and choose the macro in the current workbook. I don't want
the clients to have to do this.

Is there a property setting that tells Excel to use the macro in the new
workbook instead of the old workbook.

Thanks again for the help.

Brad






All times are GMT +1. The time now is 07:59 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com