Visio Guy

Visio Discussions => Programming & Code => Topic started by: jwspiegel on November 15, 2016, 04:39:07 PM

Title: need help with shape calling a macro
Post by: jwspiegel on November 15, 2016, 04:39:07 PM
I am using a "CustomTag" to store information about the part being dropped on the page. The tag is part of the larger stencil and i am needing to fill in two property fields when the part is first dropped on the page. My issue i'm having is my current code will change a single instance of Custom Tag if multiple are on the page but not the one that is newly dropped.I am needing only the tag that was dropped to be changed.  I am calling the macro from the events shape sheet. My test code is below. Any Help would be appreciated.

Public Sub Set_Tag()

Dim shpObj As Visio.Shape
Dim cellobj As Visio.Cell
Dim Rev_Number As Integer
Dim Proj_Number As Double
Dim TheShapes As Shapes

Rev_Number = 1
Proj_Number = 16212.01
' Obtain the list of shapes
   Set TheShapes = ActivePage.Shapes
   
   ' Holds individual shape data.
   Dim ThisShape As Shape
   Dim ShapeNames As String
   Dim showForm As String
   
   ' Obtain each shape and add it to the list.
   For Each ThisShape In TheShapes
     
       ShapeNames = ShapeNames + ThisShape.Name + vbCrLf
       If ThisShape.Name = "CustomTag" Then
         MsgBox "here"
         
          ThisShape.CellsU("Prop.Revision") = Rev_Number
          ThisShape.CellsU("Prop.Project") = Proj_Number
       
           
       End If
   
   Next
End Sub
Title: Re: need help with shape calling a macro
Post by: wapperdude on November 15, 2016, 06:49:12 PM
The newly dropped shape ought to be selected, so  just use the selected shape rather than looping thru the shapes collection.

Wapperdude
Title: Re: need help with shape calling a macro
Post by: jwspiegel on November 15, 2016, 08:35:16 PM
The issue is the tags are shapes grouped within the larger stencil... so when the stencil is dropped there are a number of shapes selected.
Browser ID: smf (is_webkit)
Templates: 1: Printpage (default).
Sub templates: 4: init, print_above, main, print_below.
Language files: 1: index+Modifications.english (default).
Style sheets: 0: .
Hooks called: 47 (show)
Files included: 25 - 925KB. (show)
Memory used: 772KB.
Tokens: post-login.
Cache hits: 7: 0.00119s for 22,302 bytes (show)
Cache misses: 1: (show)
Queries used: 9.

[Show Queries]