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

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
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,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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