We help IT Professionals succeed at work.
Get Started

How to place userForm1 neatly beside a Visio.shape at any level of screen zoom.

195 Views
Last Modified: 2016-02-11
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").left * crn) + (UserForm1.Width / 2)
        UserForm1.top = Application.top + (Me.Shapes("CmdButton1").top * 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
Comment
Watch Question
Visio Consultant, Trainer, Author, and Developer
CERTIFIED EXPERT
Most Valuable Expert 2011
Commented:
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE