Basically the code works something like this:
- Click on cell H1
- open a new window
- resize the active window to the named range ("labor")
- center active window to center of the screen
The area I'm having problems with is resizing the active window to the range selected. While it is possible to manually adjust the width and height until it works, I'd like to be able to base this off cell references. It's easy enough to get the max column (c) and row (r) from the named range, but is it possible to set the window limits to not exceed c (width) and not exceed r (height) ?
Sub NewWindow()
' open a new window
ActiveWindow.NewWindow
Worksheets("Sheet1").Activate
'remove some options to make this look more like a userform
Application.ExecuteExcel4Macro "Show.ToolBar(""Ribbon"",False)"
Application.DisplayStatusBar = Not Application.DisplayStatusBar
ActiveWindow.DisplayWorkbookTabs = False
'resize active window such that r is the max width and c is the max height
Dim r As Long, c As Long, rng As Range
Set rng = Range("Labor")
For r = 1 To rng.Rows.Count - 1
Next r
For c = 1 To rng.Columns.Count - 1
Next c
Debug.Print "row = " & r, "column = " & c
'center active window to center of screen
Dim maxWidth As Integer
Dim maxHeight As Integer
Application.WindowState = xlMaximized
maxWidth = Application.Width
maxHeight = Application.Height
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 / 4
appTop = maxHeight / 4
appWidth = maxWidth / 2
appHeight = maxHeight / 2
Application.Left = appLeft
Application.Top = appTop
Application.Width = appWidth
Application.Height = appHeight
End Sub
Bookmarks