If an element (i.e. Rectangle) should be created via VBA and it should be positioned dynamically via variables it is important that those variables (XVariable, YVariable) have to be assigned prior to the element and afterwards assigning the scaling properties (XVarMin, XViewMin, XVarMax, XViewMax, YVarMin, .... )

If the scaling properties are assigned to the element prior the variables the behaviour in the Runtime will be different (reason for that is the calculation of the scaling properties).

Find below an example how to create such an element:

Sub CreateRectangle()

    Dim zPIC As DynPicture
    Dim zELE As Element

    Set zPIC = MyWorkspace.ActiveDocument.DynPictures.Item("MyPicture")    
    If zPIC Is Nothing Then Exit Sub
    
    Set zELE = zPIC.Elements.Create("Rect_VBA", tpRectangle)
        With zELE

            'dynamic positioning variables
            .XVariable = "x_dynamic_var"
            .YVariable = "y_dynamic_var"
            
            'static element properties
            .Height = 100
            .Width = 200
            .DynProperties("StartX") = 0
            .DynProperties("StartY") = 0
 
            'dynamic width
            .XZoomVariable = "width_var"
            .XZoomVarMin = 0
            .XZoomVarMax = 100
            .XZoomViewMin = 0
            .XZoomViewMax = 100
            
            'dynamic height
            .YZoomVariable = "height_var"
            .YZoomVarMin = 0
            .YZoomVarMax = 100
            .YZoomViewMin = 0
            .YZoomViewMax = 100
            
            'x scaling position
            .XVarMin = 0
            .XViewMin = 0
            .XVarMax = 1280
            .XViewMax = 1280
            
            'y scaling position
            .YVarMin = 0
            .YViewMin = 0
            .YVarMax = 1024
            .YViewMax = 1024
        End With
    Set zELE = Nothing
End Sub