I need to interact with smart tags of individual visio.shapes to call MACRO, which will in turn:
- capture the identity of that individual shape (eg as a shapeID, objName, or via a shapesheet value).
- open userForm1, adjacent to that individual shape, at the current level of ZOOM for laptop and extension screen.
- UserForm1 receives input data affecting visio.shape properties and output data to a bound Excel wkbk.
A model sub in Excel showed ZOOM level affected whether UserForm1 launched adjacent to the visio.shape. The model used an ActiveX button 'CmdButton1' as a model shape, which I used to call this sub to position userform1 close to CmdButton1. Different zoom levels required different values of crn (correction) in this sub:
Sub CmdButton1_Click()
Dim crn As Double
crn = 0.6
UserForm1.left = Application.left + (Me.Shapes("CmdButton1").l
eft * crn) + (UserForm1.Width / 2)
UserForm1.top = Application.top + (Me.Shapes("CmdButton1").t
op * crn) + (UserForm1.Height / 2)
UserForm1.Show
End Sub
For different zoom levels, the optimal value of crn was judged by trial and error so UserForm1 remained at a const posn from CmdButton1, no matter the button was at the left or right hand side of the sheet, on the laptop screen or the extension screen. For zoom of 60%, and crn = 0.6; for zoom value 50% crn = 0.498; for zoom value 70% crn = 0.78.
2. I do not know how to automate the creation the correct crn value for the current value of ZOOM.
I am aware of API methods to convert mouse click coordinates to UserForm posn coordinates:
http://ramblings.mcpher.com/Home/excelquirks/snippets/mouseposition, but is that the method of choice?
I also read "Understanding Screen Scaling Issues"
https://msdn.microsoft.com/en-us/library/windows/desktop/ee671605(v=vs.85).aspx. but am uncertain of its relevance
3. Application.left & Application.top (see sub above) dont exist in Visio and I've not identified the equivalent Visio variable. In visio, how do I work around this to position UserForm1 next to CmdButton1?
[THE FALL-BACK is to abandon the UserForm in favour of a visio.shape, engineered to serve a similar purpose to userForm1. This WOULD simplify positioning (via "PinX", "PinY" etc) , BUT it is a less attractive alternative to a userForm. It is harder to construct, has a more limited repertoir of ctls, and is a less convenient interface for the User.]
--------------------------
-------
Hopefully, this is all subject to a well-worked solution, which is unknown to me. Otherwise, I'd be glad of advice as to where I should compromise in design to enable a practicable solution.
Competency-wise, I'm familar with handling control events via VBA classes, but by contrast would need step-by-step recipes to work with AddOns!
Many thanks
Kelvin
-- take a look in the Visio SDK for the Window.GetViewRect Method. It returns the coordinates of the specified window.
-- for crn value, a simple technique is to use two arrays (or a 2D array) to hold the zoom levels and corresponding crn values. When you determine the current zoom, select the closest zoom level in array 1, and then lookup the corresponding crn value in array 2. It's not elegant, and you're limited to the list of experimental values you've gathered, but you can probably generate other values by extrapolating from what you know. (You could also use a dictionary instead of a pair of arrays.)