+ Reply to Thread
Results 1 to 11 of 11

Anchor a form to a specific cell

  1. #1
    Registered User
    Join Date
    12-05-2006
    Location
    Philadelphia PA
    MS-Off Ver
    Office 365
    Posts
    81

    Anchor a form to a specific cell

    I want to force a VBA-created form to open (show) at a fixed location on the worksheet. Specifically, I want it to lodge in the upper left corner so the top left corner of the form completely covers cell A1. I can set the form's Top and Left properties, but those two parameters vary according to screen resolution, toolbars showing, and zoom level.

    Is there a way, programatically, to determine the pixel location of the top left corner of A1 (or any other cell) so they can be used to set the form's Top and Left properties prior to Form.Show? So far I haven't found a way to do that. Or is there some other way to position and anchor the form location to a specified worksheet cell?

    Would appreciate any words of wisdom.
    Last edited by batman; 06-20-2010 at 05:43 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Anchor a form to a specific cell

    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    12-05-2006
    Location
    Philadelphia PA
    MS-Off Ver
    Office 365
    Posts
    81

    Re: Anchor a form to a specific cell

    Thanks shg. Here's how I applied it:

    Please Login or Register  to view this content.
    But it had no effect, regardless of how I set the form's StartUpPosition property. The form appeared at the very top left of the screen, not at A1 of the worksheet. Did I apply the code wrong, or put it in the wrong place? The sub is in a code module, not the form module.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Anchor a form to a specific cell

    I don't have time to look now, but have you tried to set StartUpPosition to 3 (position in UL corner) rather than try to position it manually?

    Or see http://www.vbaexpress.com/kb/getarticle.php?kb_id=382

  5. #5
    Registered User
    Join Date
    12-05-2006
    Location
    Philadelphia PA
    MS-Off Ver
    Office 365
    Posts
    81

    Re: Anchor a form to a specific cell

    I'm working in Excel/VBA 2003, because that's what my client uses. Also, many of his clients who will use this app will have 2003 or earlier. StartUpPosition 3 on my system is Windows Default, and there is no setting for position in UL corner - wish there was.

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Anchor a form to a specific cell

    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  7. #7
    Registered User
    Join Date
    12-05-2006
    Location
    Philadelphia PA
    MS-Off Ver
    Office 365
    Posts
    81

    Re: Anchor a form to a specific cell

    Thanks RoyUK,
    Pearson notes that what I want to do is not all that simple. But he offers two solutions, including sample files. One is for modeless forms, which is what I want. It involves an API call to make the form a child of the worksheet window. It will be another day or so before I can start working on it; but it should be a good education.

    I've seen (and saved) some other Excel/VBA dissertations by Pearson. He presents the material quite well.

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Anchor a form to a specific cell

    He is one of the Excel greats.

    let us know how you get on & mark this thread solved

  9. #9
    Registered User
    Join Date
    12-05-2006
    Location
    Philadelphia PA
    MS-Off Ver
    Office 365
    Posts
    81

    Re: Anchor a form to a specific cell

    Thanks RoyUK,
    CPearson' s FormPositioner works, and I'm adapting it to my application. But it contains something completely new to me, namely: #If #Else #EndIf statements. These statements do not appear inside a procedure. In all cases they set various declarations and enums, depending on "VBA6" or not. My version of VBA is 6.5.1053 (Excel 2003).

    I've never encountered this before. Some Googling raised some references for C and C++, suggesting that the # prefix indicates conditional compiling, which sorta makes sense. But I could find nothing (including CPearson's site) that specifically addressed its use in VBA. I'd like to know more about this new-to-me subject before I incorporate it into my application. Can you (or anyone else) point me in the right direction?

    Thanks

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Anchor a form to a specific cell

    In the VBE, push the Help button, expand Microsoft Visual Basic Documentation, below that expand Visual Basic Language Reference, and below that, Directives

  11. #11
    Registered User
    Join Date
    12-05-2006
    Location
    Philadelphia PA
    MS-Off Ver
    Office 365
    Posts
    81

    Re: Anchor a form to a specific cell

    That's just the info I was looking for. Thanks for everyone's help on this topic, I'll mark it as solved.

+ 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