PDA

View Full Version : Import data from Userform to Module in powerpoint vba



dibyendu2280
05-21-2023, 05:20 AM
It may be a simple but I can not configure it out.


1. I have userform1 & where I store height & width value of my rectangle shape in form of array.
2. Now I require that value(array) in my module2.


How to import that array in module2.


Any solution will be highly appreciated.


In the Userform1


Private Sub CommandButton1_Click()
Dim h As Double
Dim w As Double
Dim port_array() As Variant
ReDim port_array(0 To 1)
h = Me.TextBoxHeight.Value
w = Me.TextBoxWidth.Value
End Sub



In the module2


Sub import_array()
Dim bshp as shape
Dim h As Double
Dim w As Double
Dim port_array() As Variant
w = port_array(0)
h = port_array(1)
Set bshp = ActivePresentation.Slides(1).Shapes("rectangle1")
With bshp
.Width = w
.Height = h
End With
End Sub

June7
05-21-2023, 08:27 AM
Why an array and not simply two variables? Why use ReDim instead of defining the array bounds when it is declared?

Your button code is not even populating array.

Possibly declare array or number variables as global?

Where do you call import_array() procedure?

dibyendu2280
05-21-2023, 08:42 AM
You are right sir, simply two variables is much easy. but how to declare variables as global in userform1.

June7
05-21-2023, 11:22 AM
You declare the variables in general module header then they can be referred to by any procedure.

dibyendu2280
05-21-2023, 11:44 AM
so, declare variable x in module2 above header. in userform1 store value in x i.e x=5. now how to get value of x in module2. I need to call
show.userform1 in module2

June7
05-22-2023, 08:19 AM
I've never used forms in PowerPoint.

Somehow a procedure opens form, user input on form sets variables, another procedure uses variables.