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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
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,215,336
Messages
6,124,338
Members
449,155
Latest member
ravioli44

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