+ Reply to Thread
Results 1 to 10 of 10

PointsToScreenPixels giving unexpected results for range width

  1. #1
    Forum Contributor
    Join Date
    03-11-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016 (among others!)
    Posts
    241

    PointsToScreenPixels giving unexpected results for range width

    So I've discovered this today after redoing a task from years ago so having a little play with it. But have noticed something I think might be odd.

    One line of useful code:
    Please Login or Register  to view this content.
    Now if the window sits in one monitor and fully maximized the answer I happen to get is 756 - which seems a fairly plausible answer as the right of column I is a little over half way across my screen.

    Now if I resize the window, but I can styill see all the columns in the range, it turns up as 1045 if I move it right. SO it almost seems to be telling me where the right edge of the range is on the screen rather than telling me the width in pixels. Is this the way it is meant to work or am I missing something? It is driving me round the twist!!

  2. #2
    Valued Forum Contributor
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    674

    Re: PointsToScreenPixels

    That's referencing column L, not column I. Is that it?

    WBD
    Excel 2016 on Windows 10, looking for rep!

  3. #3
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    UK
    MS-Off Ver
    2010 primarily
    Posts
    3,846

    Re: PointsToScreenPixels giving unexpected results for range width

    It's telling you where X points from the left hand side of the workbook window is as a screen co-ordinate, therefore it will alter if you move the window.
    Rory
    Days when we raged, we flew off the page
    Such damage was done

  4. #4
    Valued Forum Contributor
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    674

    Re: PointsToScreenPixels giving unexpected results for range width

    Quote Originally Posted by rorya View Post
    It's telling you where X points from the left hand side of the workbook window is as a screen co-ordinate, therefore it will alter if you move the window.
    I don't think this is right. On a new workbook, Range("A1").Width and Range("Z1").Width both return the same value for me i.e. the width of the range.

    WBD

  5. #5
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    UK
    MS-Off Ver
    2010 primarily
    Posts
    3,846

    Re: PointsToScreenPixels giving unexpected results for range width

    Huh? I'm talking about ActiveWindow.PointsToScreenPixelsX. If you do:

    Please Login or Register  to view this content.
    and move the window around, you should see different values, which are the X screen position of the first point of the workbook window.

  6. #6
    Forum Contributor
    Join Date
    03-11-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016 (among others!)
    Posts
    241

    Re: PointsToScreenPixels giving unexpected results for range width

    Trying to put those together my understanding was it would give me the width in pixels of A1:L1 (sorry about lower case there).

    If it is the case that it gives me the screen position rather than the pixel width if I take the same number as the left side co-ordinate of a VBA userform when it displays it does not land at the same point ie in this case not where L1 is.. Is it a different measurement for where the userform.left?
    Last edited by malcmail; 01-16-2020 at 12:01 PM.

  7. #7
    Valued Forum Contributor
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    674

    Re: PointsToScreenPixels giving unexpected results for range width

    Quote Originally Posted by rorya View Post
    Huh? I'm talking about ActiveWindow.PointsToScreenPixelsX. If you do:

    Please Login or Register  to view this content.
    and move the window around, you should see different values, which are the X screen position of the first point of the workbook window.
    Yes. Sorry. I was reading your reply incorrectly. What's odd is using this function on something that's returning a width since essentially this is function to return the screen position of a point on the active window. It would make more sense to use:

    Please Login or Register  to view this content.
    That would return the X screen coordinate of the A1 cell. If you want to know the actual width in pixels of the range perhaps you need:

    Please Login or Register  to view this content.
    It's all a bit confusing I guess.

    WBD

  8. #8
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    UK
    MS-Off Ver
    2010 primarily
    Posts
    3,846

    Re: PointsToScreenPixels giving unexpected results for range width

    If memory serves, the Left property of a userform is given in points, not pixels.

  9. #9
    Forum Contributor
    Join Date
    03-11-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016 (among others!)
    Posts
    241

    Re: PointsToScreenPixels giving unexpected results for range width

    Thanks chaps I'll give this a try. My htought process was that a number could be changed from Points to pixels. WHich it did and gave me the same result as having the range as the object instead. However knowing that it now gives me the spot on the screen of a particular item, and adding in the fact that userforms are set in points I may be able to do it the proper way now!

    Thanks again.

  10. #10
    Forum Contributor
    Join Date
    03-11-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016 (among others!)
    Posts
    241

    Re: PointsToScreenPixels giving unexpected results for range width

    Is there a reverse version of this? SO locate the edge of the screen and convert the pixels of that into points to use to locate the userform correctly?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1