控制Excel窗口大小和形状大小 [英] Controlling Excel Window size and Shape size

查看:44
本文介绍了控制Excel窗口大小和形状大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码来操纵excel窗口的窗口大小,以使窗口与形状的大小(称为背景)匹配

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?

工作簿激活模块:

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

工作簿停用模块:

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

表格更改模块:

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?

非常感谢

编辑添加的屏幕截图:背景为黑色正方形(出于保密目的,必须删除实际图像).边缘周围的白色是excel背景

Edit added screenshot: Background is black square (Had to remove actual image for confidentiality purposes). White around the edge is excel background

推荐答案

可能是因为在删除滚动条和工作簿标签等之前设置了窗口大小.您看到的空白可能是这些滚动条占用的空间.

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.

这篇关于控制Excel窗口大小和形状大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆