Create an Element

Create an Element

Here is a sample how to create a textbutton with vba...

VBA Code:
'##########################################################
'## A Procedure to create a new textbutton in a picture. ##
'## Several properties will be set and a function linked ##
'##########################################################
Sub CreateElement()
Dim zPIC As DynPicture
Dim zELE As Element
Const strPicture As String = "PictureName"
Const strElement As String = "ElementName"
Const strFunction As String = "FunctionName"
'get Picture object
Set zPIC = MyWorkspace.ActiveDocument.DynPictures.Item(strPicture)
'if picture object is nothing, the picture doesn't exist...
If zPIC Is Nothing Then Exit Sub
'get Element object
Set zELE = zPIC.Elements.Item(strElement)
'if element object is nothing, a new one can be created...
If zELE Is Nothing Then
'create a new element (Text-Button)
Set zELE = zPIC.Elements.Create(strElement, tpDynButton)
'set properties of the new element
With zELE
'set size and position
.Left = 100
.Top = 100
.Width = 150
.Height = 50
'set graphic representation
.BackColor = vbBlue
.ForeColor = vbWhite
.DynProperties("BtnStyle3D") = True
.DynProperties("BtnStyleFill") = 2
.DynProperties("BtnStyleBorder") = 0
.DynProperties("Text1") = "New TextButton"
.DynProperties("Text2") = "(created by VBA)"
'link a function
.DynProperties("Function") = strFunction
End With
End If
End Sub


This is a migrated post! Originally posted on 14.08.2007 by user robertf. Please be aware that information can be outdated.