+ Reply to Thread
Results 1 to 6 of 6

VBA to find out Height above first row?

  1. #1
    Forum Contributor
    Join Date
    09-10-2016
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    680

    VBA to find out Height above first row?

    Please Login or Register  to view this content.
    When workbook opens, the excel maximizes. I have tested the code line by line, and it does not work as I like. I think (Application.Height / 2) - (40 / 2) is the distance from B, not A. So the correct code should be Activesheet.Shapes("CommandButton1").Top = (Application.Height / 2) - (40 / 2) - h

    But how can I compute h?

    I would like to put the command button in the center of screen.

    Thanks.

    h.jpg

  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,258

    Re: VBA to find out Height above first row?

    Hello VAer,

    Your calculations my work on your computer with the current screen resolution and zoom setting. But, if these change or the Ribbon or column and row headers are hidden then you will have problems.

    To get the correct height requires using API calls to Windows.
    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 Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: VBA to find out Height above first row?

    There is probably a better way of doing this but with a little arithmetic you can determine "H" :
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Leith Ross; 01-11-2017 at 05:17 PM. Reason: Added Code Tags

  4. #4
    Forum Contributor
    Join Date
    09-10-2016
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    680

    Re: VBA to find out Height above first row?

    Thanks. I think replacing h with Application.CommandBars("Ribbon").Height works fine.

    That makes the button in the center of Excel window (including ribbon). I do mean in the center of Excel, not the center of screen. At least, it looks in the very center now.

    Thanks again.

  5. #5
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: VBA to find out Height above first row?

    Its probably my feeble mind but I'm not certain what you mean by replacing h.

    Can you show me the amended code with your changes ? Curious.

    Thanks.

  6. #6
    Forum Contributor
    Join Date
    09-10-2016
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    680

    Re: VBA to find out Height above first row?

    h is the distance between A and B, see the attached image in my first post.

    Quote Originally Posted by Logit View Post
    Its probably my feeble mind but I'm not certain what you mean by replacing h.

    Can you show me the amended code with your changes ? Curious.

    Thanks.
    Please Login or Register  to view this content.
    Last edited by VAer; 01-12-2017 at 01:27 PM.

+ 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. Replies: 0
    Last Post: 02-13-2016, 03:31 AM
  2. Replies: 4
    Last Post: 03-21-2015, 08:18 PM
  3. Replies: 2
    Last Post: 01-12-2015, 02:52 PM
  4. Macro to autofit row height, and then reduce back to original height
    By LesleyRicco in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-03-2013, 09:12 PM
  5. Find time associated with half-height
    By jtillema in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 01-07-2011, 12:49 PM
  6. Replies: 17
    Last Post: 02-25-2009, 10:09 AM
  7. [SOLVED] find the printable page height
    By Derk in forum Excel General
    Replies: 0
    Last Post: 03-15-2006, 11:45 AM

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