View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Desmond Walsh Desmond Walsh is offline
external usenet poster
 
Posts: 28
Default Is it possible to copy vba macros into a workbook using a vbamacro to do the copying

On Sunday, April 10, 2016 at 1:02:14 PM UTC-4, Desmond Walsh wrote:
I have a series of workbooks one for each year handling budgetary data that prepares tax information for the year in question. If I modify a macro or add a new macro, I have to manually make the modification in each of the workbooks (12 in all). Each workbook has links back to the preceding workbook so that cumulative data from year 1 can be presented in the current year.

I would like to make the VBA changes in the base year's workbook and then migrate that changed macro to all the other 11 workbooks using VBA code. Is this possible ?.

I am already using PERSONAL.XLSM to hold a library of commonly used macros. However, I think it is poor design to place macros common to one particular series of workbooks in PERSONAL.XLSM.

Looking forward to being enlightened. Thank you.


Actually, I found a VBA macro CopyModule on Chip Pearson's webite www.cpearson.com that does exactly what I want. The following test code shows how to use this macro.

Sub test_CopyModule()
'
' A test procedure to test the Vba macro CopyModule
' NOTE 1: CopyModule is from Chip Pearson's site www.cpearson.com
' (check topic VBA EDitor, Automating The VBA EDitor and its objects)
' NOTE 2: The module may be any VBComponent such as ThisWorkbook, ModuleN,
' SheetN or any form in Forms
' Updated: 10-Apr-2016
'---------------------------------------------------------------------------
Dim result As Boolean
Dim FromVBProject As VBIDE.VBProject
Dim ToVBProject As VBIDE.VBProject
Dim from_wb As Workbook
Dim to_wb As Workbook

Set from_wb = Workbooks("Tax_Section216_2005.xlsm")
Set to_wb = Workbooks("test_copy_macro.xlsm")

Set FromVBProject = from_wb.VBProject
Set ToVBProject = to_wb.VBProject

result = CopyModule("Module1", FromVBProject, ToVBProject, True)
End Sub