'Controlling Excel Window size and Shape size
I have a couple of bits of code to manipulate the window size of the excel window to make the window match to the size of the shape (named background)
My problem is, is that the height and width of the shape and the window, don't match.
Is there something that I am missing? Shouldn't pixels equate to pixels?
Workbook activate module:
Private Sub Workbook_Activate()
' Hide Ribbon and Controls
Dim Background As Shape
Set Background = ThisWorkbook.ActiveSheet.Shapes("Background")
With Application
.ScreenUpdating = False
.ExecuteExcel4Macro "SHOW.TOOLBAR(""RIBBON"", FALSE)"
.DisplayFormulaBar = False
.WindowState = xlNormal
.Height = Background.Height
.Width = Background.Width
.DisplayStatusBar = False
End With
With ActiveWindow
.DisplayHeadings = False
.DisplayWorkbookTabs = False
.DisplayHeadings = False
.DisplayHorizontalScrollBar = False
.DisplayVerticalScrollBar = False
.ScrollColumn = 1
.ScrollRow = 1
End With
End Sub
Workbook Deactivate module:
Private Sub Workbook_Deactivate()
' Show all Controls and Ribbon
With Application
.ScreenUpdating = False
.ExecuteExcel4Macro "SHOW.TOOLBAR(""RIBBON"", TRUE)"
.DisplayFormulaBar = True
End With
With ActiveWindow
.DisplayHeadings = True
.DisplayWorkbookTabs = True
.DisplayHeadings = True
.DisplayHorizontalScrollBar = True
.DisplayVerticalScrollBar = True
End With
End Sub
Sheet Change module:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim Background As Shape
Set Background = Nothing
On Error Resume Next
Set Background = Sh.Shapes("Background")
On Error GoTo 0
If Not Background Is Nothing Then
With Application
.WindowState = xlNormal
.Height = Background.Height
.Width = Background.Width
End With
With ActiveWindow
.ScrollColumn = 1
.ScrollRow = 1
End With
End If
End Sub
Could someone help as to why these don't match?
Many Thanks
Edit added screenshot: Background is black square (Had to remove actual image for confidentiality purposes). White around the edge is excel background

Solution 1:[1]
try this and let me know what you think :
After the line:
Set Background = ThisWorkbook.ActiveSheet.Shapes("Background")
add:
Background.Left = 0
Background.Top = 0
Solution 2:[2]
It can be because you set the window size before you remove scrollbars and workbooktabs etc. The empty space you see is probably the space these scrollbars ... took.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | El Scripto |
| Solution 2 | Bhargav Rao |
