+ Reply to Thread
Results 1 to 10 of 10

Popup Box location

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-21-2013
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2010
    Posts
    186

    Popup Box location

    Gurus,

    Is there a way to specify the location (position relative to the active cell) as to where a popup box will open?

    TIA,
    Tim

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Popup Box location

    Hello Tim,

    What type of popup are you referring to? An Application.InputBox will allow you to select the position. A MsgBox defaults to the center of the screen. It is possible to change but it requires a lot of API code and is not really worth the time and effort.

    You can also use a UserForm to create a custom popup. It can be positioned where you want with a little extra coding.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor
    Join Date
    06-21-2013
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2010
    Posts
    186

    Re: Popup Box location

    Leith,

    I am not sure if you received the thread that I sent a few days ago.

    To answer your question, the box was created using UserForm.

    Is the code to position that popup difficult? Any help would be appreciated.

    Thanks,
    Tim

  4. #4
    Forum Contributor
    Join Date
    06-21-2013
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2010
    Posts
    186

    Re: Popup Box location

    Leith,

    I should have been more specific. The box was created using Userform. I named it frmCalendar if that helps. I was hoping that code could be written.

    Basically, I have it set up so that when the user clicks on any cell in row2, the Calendar box pops up. However, it pops up in the middle of the worksheet. I would like to get it to pop up closer to row2.

    Tim

  5. #5
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Popup Box location

    Hi Tim

    This is the Code I use.
    '****************************************************
     'The 2 macros below are mutually exclusive, use one OR the other
     '****************************************************
     
     '<< Code for userform (macro 1) >>
    Option Explicit 
     
    Private Sub UserForm_Activate() 
        With UserForm1 
            .Top = Application.Top + 125 '< change 125 to what u want
            .Left = Application.Left + 25 '< change 25 to what u want
        End With 
    End Sub 
     
     
     
     
     'OR use
     
    Option Explicit 
     
     Private Sub UserForm_Activate() 
        With UserForm1 
            .Top = 125 '< change 125 to what u want
            .Left = 25 '< change 25 to what u want
        End With 
    End Sub
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  6. #6
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Popup Box location

    Hi Tim,
    maybe this example will be useful for you (see attachment)
    Attached Files Attached Files

  7. #7
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Popup Box location

    Maybe something like this

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim intXoffset As Integer
    Dim intYoffset As Integer
        If Not Intersect(ActiveCell, Rows(2)) Is Nothing Then
            Load frmCalendar
            With frmCalendar
                .StartUpPosition = 0
                intXoffset = ActiveWindow.PointsToScreenPixelsX(Range("A1"))
                intYoffset = ActiveWindow.PointsToScreenPixelsY(Range("A1"))
                .Top = intYoffset '+ ActiveCell.Top
                .Left = intXoffset + ActiveCell.Left
                .Show
            End With
        End If
    End Sub
    If you are pleased with a member's answer then use the Star icon to rate it.

  8. #8
    Forum Contributor
    Join Date
    06-21-2013
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2010
    Posts
    186

    Re: Popup Box location

    Thank you all for your input.

    For some reason or another the only one that worked was Buran's code. However, I tweaked it a bit with code from the others.

    Below is what I ended up with.

    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Dim intXoffset As Integer
    Dim intYoffset As Integer
    If Intersect(Target, Range("a2:a30")) Is Nothing Then Exit Sub
    Cancel = True
    With frmCalendar
        .StartUpPosition = 0
        intXoffset = ActiveWindow.PointsToScreenPixelsX(Range("c2"))
        intYoffset = ActiveWindow.PointsToScreenPixelsY(Range("c2"))
        .Top = intYoffset + ActiveCell.Top - 150
        .Left = intXoffset + ActiveCell.Left + 175
        .Show
    End With
    End Sub
    FYI - until I changed the range to c2 in the intXoffest and intYoffset lines, it failed. Seems like it had to do with the size of columns A and B as well as the size of the UserForm.

    Thanks Again!!!
    Tim

  9. #9
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Popup Box location

    Hi Tim

    The Code I provided would go into the Private Sub UserForm_Activate() event.

  10. #10
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Popup Box location

    the others have StartUpPosition property of the user form set to manual at design time and they didn't mention it in their posts. I had it in my code, set on the fly, and that's why mine works.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Popup Calendar Location
    By welshman010 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-04-2014, 08:48 PM
  2. popup alert message during the worksheet open and continuous work on the sheet popup jump
    By shailkam2001 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-04-2014, 10:24 AM
  3. [SOLVED] [Help]macro to open file browser, to select a location, and save the location to a cell
    By zhuleijia in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-06-2013, 09:56 AM
  4. Replies: 5
    Last Post: 04-08-2010, 01:01 AM
  5. MsgBox PopUp based on ActiveCell Location!
    By BigBas in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-31-2007, 02:37 AM

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