Author Topic: Data resources in VBA code  (Read 2851 times)

0 Members and 1 Guest are viewing this topic.


  • Hero Member
  • *****
  • Posts: 2952
Data resources in VBA code
« on: January 31, 2022, 04:38:45 AM »
Say you have code which relies on bigger data resources - in my case the list of all standard shapesheet cells.
If I wanted to avoid writing this list directly in the VBA code to keep it maintainable, I would like to save this list in a resource file.
One neat solution could consist of a simple shape in which you put the list as its text.
You would then drop this shape to the stencil of your solution and name it as desired.
Your code can now access this list by means of the following macro.

Function getMasterText(stencilName As String, masterName As String) As String
    Dim stencil_ As Document
    Set stencil_ = Documents(stencilName)
    Dim Mstr As Master
    Set Mstr = stencil_.Masters(masterName)
    Dim shp As Shape
    Set shp = Mstr.Shapes(Mstr.Shapes.Count)
    getMasterText = shp.Text
End Function
« Last Edit: January 31, 2022, 04:52:22 AM by Yacine »