Announcement

Collapse
No announcement yet.

Set Excel window position to center

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Set Excel window position to center



    I have this code that sets the workbook's size...
    Code:
    Application.WindowState = xlNormal
    Application.Width = 750
    Application.Height = 620
    ...now I need help on a code that will position the excel window on the center of the screen
    no matter what size/resolution the user have.

    Please help! Thanks in advance

  • #2
    Re: Set Excel window position to center

    This looks promising: Center application
    AAE
    ----------------------------------------------------

    Forum Rules | Message to Cross Posters | How to use Tags

    Comment


    • #3
      Re: Set Excel window position to center

      One reply from the master "AAE" solves the problem I've been having over a week, Thank you!
      I played with the numbers to suit my need and got it working as to resizing excel app window to its minimum and show the form as it would look like a stand alone application. I've tried to hide excel completely but it left the form dead to function.

      Code:
      Private Sub Workbook_Open()
          Dim maxWidth As Integer
          Dim maxHeight As Integer
          Application.WindowState = xlMaximized
          maxWidth = Application.Width
          maxHeight = Application.Height
          Call CenterApp(maxWidth, maxHeight)
      End Sub
      
      
      Sub CenterApp(maxWidth As Integer, maxHeight As Integer)
          Dim appLeft As Integer
          Dim appTop As Integer
          Dim appWidth As Integer
          Dim appHeight As Integer
          Application.WindowState = xlNormal
          appLeft = maxWidth / 2
          appTop = maxHeight / 2
          appWidth = maxWidth / 16
          appHeight = maxHeight / 30
          Application.Left = appLeft
          Application.Top = appTop
          Application.Width = appWidth
          Application.Height = appHeight
      End Sub
      Thanks again AAE!

      Comment


      • #4


        Re: Set Excel window position to center

        Glad it worked for you and thanks for posting the final code.
        AAE
        ----------------------------------------------------

        Forum Rules | Message to Cross Posters | How to use Tags

        Comment

        Working...
        X