How to check selected tool in the toolbar

B

Bony Baba

Hi
can we know programatically whether user click the pointer tool button in
standard toolbar or reactangle tool in the drawing toolbar.

Thanks
 
C

Chris Roth [MVP]

Hi BB,

This code seems to work. Try pasting it in a Document class inside the VBA
editor (Alt + F11 will get you there quickly)

If you click the blue-triangle on the Developer toolbar off, then on, the
sub "Document_RunModeEntered" will execute, and set up your WithEvents
m_visApp variable to receive the events.

In this example, the Debug window (Immediate Window) will tell you when
you've selected the Pointer, Line, or Rectangle tool.

-------------------

Private WithEvents m_visApp As Visio.Application

Private Sub Document_RunModeEntered(ByVal doc As IVDocument)
Set m_visApp = ThisDocument.Application
End Sub

Private Sub m_visApp_EnterScope(ByVal app As IVApplication, ByVal nScopeID
As Long, ByVal bstrDescription As String)

If nScopeID = Visio.VisUICmds.visCmdDRLineTool Then
Debug.Print "Line tool selected"
End If

If nScopeID = Visio.VisUICmds.visCmdDRRectTool Then
Debug.Print "Rectangle tool selected"
End If

If nScopeID = Visio.VisUICmds.visCmdDRPointerTool Then
Debug.Print "Pointer tool selected"
End If

End Sub

-------------------
--
Hope this helps,

Chris Roth
Visio MVP

Free Visio shapes:
http://www.visguy.com/category/shapes
Visio programming info:
http://www.visguy.com/category/programming/
Other Visio resources:
http://www.visguy.com/visio-links/
 
B

Bony Baba

Hi Chris
Thanks a lot , it solves my prop

Chris Roth said:
Hi BB,

This code seems to work. Try pasting it in a Document class inside the VBA
editor (Alt + F11 will get you there quickly)

If you click the blue-triangle on the Developer toolbar off, then on, the
sub "Document_RunModeEntered" will execute, and set up your WithEvents
m_visApp variable to receive the events.

In this example, the Debug window (Immediate Window) will tell you when
you've selected the Pointer, Line, or Rectangle tool.

-------------------

Private WithEvents m_visApp As Visio.Application

Private Sub Document_RunModeEntered(ByVal doc As IVDocument)
Set m_visApp = ThisDocument.Application
End Sub

Private Sub m_visApp_EnterScope(ByVal app As IVApplication, ByVal nScopeID
As Long, ByVal bstrDescription As String)

If nScopeID = Visio.VisUICmds.visCmdDRLineTool Then
Debug.Print "Line tool selected"
End If

If nScopeID = Visio.VisUICmds.visCmdDRRectTool Then
Debug.Print "Rectangle tool selected"
End If

If nScopeID = Visio.VisUICmds.visCmdDRPointerTool Then
Debug.Print "Pointer tool selected"
End If

End Sub

-------------------
--
Hope this helps,

Chris Roth
Visio MVP

Free Visio shapes:
http://www.visguy.com/category/shapes
Visio programming info:
http://www.visguy.com/category/programming/
Other Visio resources:
http://www.visguy.com/visio-links/
 

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