Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to store elements of array permanently in VBA in Excel?

I wrote macro in Excel that uses dynamic array. Users will add elements to that array.

Is it possible to store elements permanently, so the elements will be available even after workbook was closed?

The trick is that I do not want to store elements on a worksheet and insert them back to array when workbook is open, but to have elements permanently saved in array.

like image 615
user652061 Avatar asked Sep 28 '11 21:09

user652061


2 Answers

One of your best bets is to store the array values in a worksheet and mark the worksheet as hidden using VBA.

Me.Worksheets("ArrayValuesWorksheet").Visible = False

If you use other things like local CSV files, registry, etc then the code will behave differently by simply moving the workbook to different machines and you will lose the ability to have multiple copies of the array.

Edit (Excellent suggestion in @Reafidy's comments below)

like image 199
Raj More Avatar answered Nov 14 '22 23:11

Raj More


You can also store an array in a name from the names collection, and this name can be hidden.

Names.Add Name:="StoredArray", RefersTo:=myArray, Visible:=False
like image 31
RonnieDickson Avatar answered Nov 14 '22 23:11

RonnieDickson