Move and delete shape

S

stijn

Adding a shape on a page generates an event.
Since we're working with a propertie database which is maintained by VBA,
we would offcourse also wanna know when a shape is moved or deleted.

However, as far as I see, there are no events in VBA for these actions.

Can I do this some other way?

Thanks and greetings, Stijn
 
A

Al Edlund

there are events for cell changed (you might monitor for pinx/piny
locations) as well as beforeshapedelete.
al
 
S

stijn

Where can I see those events? They are not listed under 'thisdocument', only
: 'documentchanged'-event and others, but nothing with cells or shapes
(except ShapeAdded)

I can only find them in the help file, but nowhere to use them.
 
S

stijn

Found it. I've added "Private WithEvents vsoApplication As Application" and
now i can find the other events.
Thanks anyway
 
S

stijn

Sorry to bother you again, Al, but the events are not 'alive'.
It seems I can program them now, but they are not activated.

According to the help, it seems I need to use 'AddAdvise'.
I tried this with a small piece of code from the help file, but I get
errors : He doesn't seem to know this type : clsEventSink in :
Private mEventSink As clsEventSink.

This is going way over my head, could you pls provide me with
some explanation?

thx

Stijn
 
A

Al Edlund

I use something like this
al


' for event management

Private WithEvents pagObj As Visio.Page
Private WithEvents appObj As Visio.Application
Private WithEvents shpObj As Visio.Shape
Private WithEvents winObj As Visio.Window
Private WithEvents docObj As Visio.Document



' initialize the document stuff
Public Sub Document_DocumentOpened(ByVal doc As IVDocument)


On Error GoTo DocumentOpened_Err

Set pagObj = Visio.ActivePage
Set appObj = Visio.Application
Set winObj = Visio.ActiveWindow
Set docObj = Visio.ActiveDocument

ActiveWindow.DeselectAll

' initialize our globals with constants

' Debug.Print "Document Opened"


Exit Sub

DocumentOpened_Err:

If Err > 0 Then
Debug.Print "Err in DocumentOpenedEvent " & Err & " " & Err.Description
End If


End Sub

' find out what was selected
Private Sub winObj_SelectionChanged(ByVal Window As IVWindow)

Dim objcell As Visio.Cell
Dim objShapes As Visio.Shapes
Dim objShape As Visio.Shape
Dim strIPAddress As String
Dim strNetStatus As String
Dim intObjCount As Integer
Dim itmx As ListItem


On Error GoTo ErrorHandler

' clear the list and rewrite it

If ActiveWindow.Selection.Count > 0 Then
'Debug.Print ActiveWindow.Selection.Count & " devices selected"
For intObjCount = 1 To ActiveWindow.Selection.Count
Set objShape = ActiveWindow.Selection.item(intObjCount)

' do something with the selections

Next intObjCount

End If ' test for selection count

Exit Sub

ErrorHandler:

If Err > 0 Then
Debug.Print "Err in Cell Selected " & Err & " " & Err.Description
Resume Next
End If


End Sub

' find out what cell was changed (happens a lot)
Private Sub pagObj_CellChanged(ByVal Cell As IVCell)

dim strCellName as string
On Error GoTo CellChanged_Err

Set visShape = Cell.Shape
strCellName = LCase(Cell.Name)

' do something with it

Exit Sub

CellChanged_Err:

If Err > 0 Then

Debug.Print "Err in Cell Changed " & Err & " " & Err.Description
Debug.Print " cell changed " & Cell.Name

End If

End Sub
 
D

David Parker

I think that FormulaChanged event for PinX & PinY is more efficient than
CellChanged, as CellChanged fires far more frequently.
Even having an empty CellChanged event statement slows things down...
 
A

Al Edlund

David,
Thanks for the tip,
al

David Parker said:
I think that FormulaChanged event for PinX & PinY is more efficient than
CellChanged, as CellChanged fires far more frequently.
Even having an empty CellChanged event statement slows things down...
 
S

stijn

Hi Al,

Don't know what's wrong here, pulled al my hair from my head ...

I tried your example, but those events don't get triggered either ...

Only the 'standard' events which are in Visio's VBA, get triggered, not the
other ones ...
Could this be some setting or what?

pls help,

Stijn
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top