这是由于在您的本机屏幕分辨率更改时打开文件引起的问题(并且可能仅在这也更改纵横比时) - 将笔记本电脑连接或断开连接到/的最常见原因从外部屏幕(在这种情况下,通过您的扩展坞)
此问题有两种形式:按钮保持相同大小,但内容(文本、图像等)在左上角锚定时按比例放大/缩小 - 这就是这里发生的情况 -或者内容保持相同大小,但按钮本身会变大/变小,直到它覆盖整个工作表或太小而无法单击。
根据我的经验,修复按钮的唯一方法是调整它们,并强制 Excel 重新绘制形状,而不是“记住”它应该是什么样子。您可以手动执行此操作,但我会尝试找到一些代码来为您“重置”按钮。 这里有一些代码可以为您做事。
(对于用户窗体,您可能只需调用 Me.Repaint 即可强制重绘,而无需费心调整大小 - 但我尚未对此进行测试,因为我永远无法做到这一点按需发生的问题>_
用户窗体按钮修复
Sub FixButtonFormat(ByRef Button As Control)
Dim Top As Double, Left As Double, Width As Double, Height As Double, FontName As String, FontSize As Double
Top = Button.Top
Left = Button.Left
Width = Button.Width
Height = Button.Height
FontName = Button.Object.Font.Name
FontSize = Button.Object.Font.Size
'Scale Button up slightly
Button.Top = Top - 1
Button.Left = Left + 1
Button.Width = Width - 2
Button.Height = Height + 2
Button.Object.Font.Size = FontSize + 1
DoEvents
UserForm1.Repaint
DoEvents
'Reset button to original size
Button.Top = Top
Button.Left = Left
Button.Width = Width
Button.Height = Height
Button.Object.Font.Name = FontName
Button.Object.Font.Size = FontSize
End Sub
工作表按钮修复
Sub FixButtonFormat(ByRef Button As Shape)
If Button.Type <> msoFormControl And Button.Type <> msoOLEControlObject Then Exit Sub
Dim Top As Double, Left As Double, Width As Double, Height As Double, FontName As String, FontSize As Double
Dim Screen As Boolean
Screen = Application.ScreenUpdating
Top = Button.Top
Left = Button.Left
Width = Button.Width
Height = Button.Height
If Button.Type = msoFormControl Then 'Form Control
FontName = Button.OLEFormat.Object.Font.Name
FontSize = Button.OLEFormat.Object.Font.Size
ElseIf Button.Type = msoOLEControlObject Then 'ActiveX Control
FontName = Button.DrawingObject.Object.Font.Name
FontSize = Button.DrawingObject.Object.Font.Size
End If
'Scale Button up slightly
Button.Top = Top - 1
Button.Left = Left + 1
Button.Width = Width - 2
Button.Height = Height + 2
If Button.Type = msoFormControl Then 'Form Control
Button.OLEFormat.Object.Font.Size = FontSize + 1
ElseIf Button.Type = msoOLEControlObject Then 'ActiveX Control
Button.DrawingObject.Object.Font.Size = FontSize + 1
End If
If Not Screen Then
Application.ScreenUpdating = True
DoEvents
Application.ScreenUpdating = False
Else
DoEvents
End If
'Reset button to original size
Button.Top = Top
Button.Left = Left
Button.Width = Width
Button.Height = Height
If Button.Type = msoFormControl Then 'Form Control
Button.OLEFormat.Object.Font.Name = FontName
Button.OLEFormat.Object.Font.Size = FontSize
ElseIf Button.Type = msoOLEControlObject Then 'ActiveX Control
Button.DrawingObject.Object.Font.Size = FontSize
Button.DrawingObject.Object.Font.Name = FontName
End If
End Sub