Previous Document Next Document

Object Model Reference : Classes : S : Shape : Properties : Shape.StaticID


Shape.StaticID

Property StaticID As Long

Description

Member of Shape

The StaticID property returns an integer representing a unique ID number assigned to each shape. This number does not change and can therefore be used throughout the lifetime of the shape.

The StaticID property returns a read-only value.

VBA example 1

The following VBA example stores the current selection in the array of the active page properties.

Sub SaveSelection()
 Dim s As Shape, n As Long
 ActivePage.Properties("StoredSelection", 0) = ActiveSelection.Shapes.Count
 n = 1
 For Each s In ActiveSelection.Shapes
  ActivePage.Properties("StoredSelection", n) = s.StaticID ' Store the current shape's ID number
  n = n + 1
 Next s
End Sub
VBA example 2

The following VBA example restores the selection that was saved in the properties of the active page in the previous example.

Sub RestoreSelection()
 Dim s As Shape, sr As New ShapeRange
 Dim v As Variant
 Dim Num As Long, i As Long, id As Long
 v = ActivePage.Properties("StoredSelection", 0) ' Retrieving the total number of shape references stored
 If Not IsNull(v) Then
  ActivePage.Properties.Delete "StoredSelection", 0 ' Delete the property
  Num = v
  For i = 1 To Num
   id = ActivePage.Properties("StoredSelection", i) ' Getting the current shape's ID to find
   Set s = ActivePage.FindShape(StaticID:=id)
   If Not s Is Nothing Then sr.Add s ' Add the shape to the shape range if it still exists in document
   ActivePage.Properties.Delete "StoredSelection", i ' Delete the property
  Next i
  sr.CreateSelection ' Selects all shapes found
 Else
  MsgBox "No selection stored in the active page"
 End If
End Sub

 
You can use the Page.FindShape or Layer.FindShape methods to locate a shape based on its unique ID.

Previous Document Next Document Back to Top

Copyright 2013 Corel Corporation. All rights reserved.