Custom Functions

smpatty08

Board Regular
Joined
May 16, 2014
Messages
155
I have some custom functions that I would like to be used in every excel file I open (if it isn't already in there). I know I can use my Personal Workbook to do this, but I frequently send/share spreadsheets with other people I work with and it is not feasible to copy the functions to everybody's personal workbook. So, my thought is that is I could have a code in my personal workbook that when I open any excel file it inputs the function codes into the ThisWorkbook module. I have tried the following code that works but it puts the macro into the ThisWorkbook module in my Personal Workbook.
Code:
Sub Add_Macro_To_ThisWorkbook()


Dim VBP As VBProject
Dim VBM As VBComponent
Dim VBModule As CodeModule
Dim VBProc As VBComponent


Set VBP = ThisWorkbook.VBProject


Set VBModule = VBP.VBComponents.Item("ThisWorkbook").CodeModule


VBModule.AddFromString ("Sub Sample_Macro" & vbCrLf & "ret = msgbox (""Hello VBADUD"") " & vbCrLf & "End Sub")


End Sub

Does anybody have any ideas how this can be done?
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
I guess you could open a new workbook, add the code wherever you want it, save the workbook as a Template and then when you open a new workbook, open the Template instead and any code you added will automatically be there.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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
Back
Top