Click here to Skip to main content
14,578,986 members
Rate this:
Please Sign up or sign in to vote.
See more:
about a year ago, I searched this forum and I saw a sample (.NET) showing the form in a relative position compared to the specified cell,
In VBA, I would need to use a fairly sophisticated API to do this, but now I can use .NET. No more remembering the keyword to find it. I tried searching and it looks like I will need "PointsToScreenPixelsY" and "PointsToScreenPixelsX" but I'm worried that I might miss anything..
Can you give me a solution?
Many thanks!

What I have tried:

With ActiveWindow
    UserForm1.Left = .PointsToScreenPixelsX(cell.Left)
    UserForm1.Top = .PointsToScreenPixelsY(cell.Top)
End With
Updated 27-Apr-20 2:49am
Rate this:
Please Sign up or sign in to vote.

Solution 2

PointsToScreenPixelsX and PointsToScreenPixelsY are Excel methods of a Window, or a Pane.

The values returned are pixel values; to set a Form's position, you must convert the pixel values to Points. See: [^].

You can find what appears to be a complete solution for your question here: [^].

Caution: I do not have Excel on this machine, and cannot test this using C# automation.
Maciej Los 30-Apr-20 1:31am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100