1、打开excel2010可以看到右下角小三角,拖住小三角移动,可以改变窗口的的大小(任意修改),那如何设置400*200的窗口呢?使用VBA可以修改修改大小吗?答案是肯定的。
2、打开VBA编辑前,新建一个模块命名:模块1。
3、在模块1中输入以下程序:
Public Sub 设置工作簿窗口大小()
Dim wd As Window
Dim myWState As Long, myWidth As Double, myHeight As Double
Set wd = ActiveWindow
With wd
myWState = .WindowState
.WindowState = xlNormal 'xlMaximized -4137 最大化 xlMinimized -4140 最小化 xlNormal -4143 正常
myWidth = .Width
myHeight = .Height
MsgBox ("现在窗口的大小:" & myWidth & "*" & myHeight)
.Width = 400 '设定窗口的宽度
.Height = 200 '设定窗口的高度
If MsgBox("窗口大小已经被改变!" _
& vbCrLf & "是否恢复至原来的大小?" _
, vbInformation + vbYesNo) = vbNo Then Exit Sub
.Width = myWidth
.Height = myHeight
.WindowState = myWState
End With
Set wd = Nothing
End Sub
4、 单击运行,可以看到窗口已经修改为400*200。
本文使用Windows版本:Windows xp sp3 Excel版本:Excel 2010