Doctor P
Doctor P

Reputation: 65

Convert String To Property or Object (VBA)

I am building an array in VBA for Powerpoint.

The sub sweeps through all shapes in each slide in the presentation, and I want to store into the array:

  1. The property (as string or object)
  2. The value of that property.

I will then load this array into a list box. When the user clicks on the selected item in the list box I want the property to be set with the value.

In code it would be something like this:

Dim s_MyProperty as string
Dim s_Value as string

'Remember the variables
s_MyProperty = ".PageSetup.SlideHeight"
s_Value = ActivePresentation.PageSetup.SlideHeight

' This is the part I need help with
' Apply the property
Dim o_Object as object ' or something similar
o_Object = ActivePresentation
o_Object &  s_MyProperty = s_Value 

The code would be similar in Excel.

Any ideas?

Upvotes: 2

Views: 5934

Answers (1)

Cool Blue
Cool Blue

Reputation: 6476

check out the CallByName function... its an oldie but a goodie.

CallbyName o_Object, s_MyProperty, VbLet, s_Value

Upvotes: 4

Related Questions