Results 1 to 12 of 12

Thread: [RESOLVED] PointsToScreenPixelsX

  1. #1

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,344

    Resolved [RESOLVED] PointsToScreenPixelsX

    I assume that PointsToScreenPixelsX comes into play if I want to align the top of my userform with the top of a cell, but what is the statement that does that? Would it be affected by either the position of the Excel window or the worksheet's zoom value?

  2. #2

  3. #3

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,621

    Re: PointsToScreenPixelsX

    i think this one will do what you want with minimum changes

    http://www.cpearson.com/excel/SetParent.aspx
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,344

    Re: PointsToScreenPixelsX

    Thanks, Chip has some remarkable code on his site but I don't see how the link helps me to align the top of my userform with the top of a cell. In my question I simplified it a bit in that I also want to align it at the left edge of the selected cell so that it look like this.
    Name:  2022-07-19_09-36-31.png
Views: 67
Size:  68.4 KB

  6. #6
    Member
    Join Date
    May 2021
    Posts
    32

    Re: PointsToScreenPixelsX

    There is a Userform positioner on Chip's site somewhere that does (from what I can gather) exactly what you're after: http://www.cpearson.com/Excel/FormPosition.htm

    [Edit] Found the link: http://www.cpearson.com/Zips/formposition.ZIP

    Name:  FormPos1.jpg
Views: 42
Size:  16.0 KB

    (Many thanks to westconn1 for the reminder.)

  7. #7

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,344

    Re: PointsToScreenPixelsX

    Thanks but I tried that already and couldn't get the userform to even come close to where I wanted it. Here is the code I used
    Code:
    Sub Marty()
    Dim PS As Positions
        Range("H10").Select
        frmMine.StartupPosition = 0
        PS = PositionForm(frmMine, ActiveCell, 0, 0, cstFhpFormLeftCellLeft, cstFvpFormTopCellTop)
        frmMine.Top = PS.FrmTop
        frmMine.Left = PS.FrmLeft
        frmMine.Show vbModeless 'vbModal
    End Sub
    In my situation I need to show the forn modeless but it made no difference if I showed the form modally.

  8. #8
    Member
    Join Date
    May 2021
    Posts
    32

    Re: PointsToScreenPixelsX

    This approach appears to work - here. It will work modelessly too.

  9. #9

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,344

    Re: PointsToScreenPixelsX

    Thanks. It sort of works. In my workbook I have several userforms and in the DisplayUserForm sub I changed date_Form to the name of the userform I wanted to position and I changed Activecell to the range where I wanted it displayed. When I called DisplayUserForm, believe it or not, it displayed the wrong userform but in the right place!

  10. #10

  11. #11
    Member
    Join Date
    May 2021
    Posts
    32

    Re: PointsToScreenPixelsX

    Quote Originally Posted by MartinLiss View Post
    I bet it only works if the workbook only has one userform, or, if there's more than one userform, it shows the one that Excel determines is the first one.
    I made an array(1 to 4) of a basic userform, and it cycled through each of them each time I clicked on a certain cell, repositioning the relevant UserForm to be offset(0, 1) from the selected cell, as per the image below.

    Code:
    Sub PositionForm(ByVal objUserForm As Object, ByVal objPosCell As Range)
    I find it's just a matter of calling the PositionForm subroutine with the userform object, and the target cell. I'm not sure why you're experiencing such odd, random userform placements.


    Attachment 185332
    Attached Images Attached Images  

  12. #12

Posting Permissions

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



Click Here to Expand Forum to Full Width