using vba to copy array constants names and definitions from one workbook to another

Joined
Jan 12, 2013
Messages
1
I have two workbooks, one for last year's dataset and another for this years. I use a lot of array constants. I would like to copy the array constant names and definitions from one workbook to the other. How can I do this in VBA?
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Welcome to MrExcel,

My approach to this would be to create a Module that has the information you wish to pass from one workbook to another. Export the module (after any changes that are needed). For this demo, I named the Module “ArraysToSave” and exported it to a file: "c:\temp\arr.bas". You could do this manually, but where’s the fun in that?


To export with VBA:

Code:
ActiveWorkbook.VBProject.VBComponents("ArraysToSave").export "c:\temp\arr.bas"

To import that file to another workbook,:

Code:
ActiveWorkbook.VBProject.VBComponents.Import "c:\temp\arr.bas"
Application.Run "SetupArr"

Where SetupArr is a sub to do any legwork to get the arrays stuffed with constants and is in the file "c:\temp\arr.bas"

My arr.bas is:

Code:
Public arr
Sub SetupArr()
    arr = Array("Dog", "Horse", "Rain")
End Sub
Sub exportArr()
    ActiveWorkbook.VBProject.VBComponents("ArraysToSave").export "c:\temp\arr.bas"
End Sub

So, after the import and running SetupArr, the array arr is stuffed with "Dog", "Horse", "Rain" and may be used in the “normal” array statements.
 
Upvote 0

Forum statistics

Threads
1,214,951
Messages
6,122,446
Members
449,083
Latest member
Ava19

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