【问题标题】:Catastrophic Failure - Out of Memory when opening a User Form灾难性故障 - 打开用户表单时内存不足
【发布时间】:2020-06-17 05:55:08
【问题描述】:

我有一个 VBA 程序,可以打开一系列用户表单。
我在笔记本电脑上设计了整个东西,并在其他一些笔记本电脑上进行了测试。在 Excel 2010 和 2016 中。

我与使用不同风格笔记本电脑(Win7、Office 2010)的同事分享了它。每次他们点击按钮打开用户窗体时,他们都会遇到灾难性故障,内存不足错误。

我在网上看到模块应该小于 64kb。用于打开按钮的模块非常小(只打开了 UserForm1)。

Userform frm 文件为 4 KB。
Userform frx 文件为 1.24 MB,较大是因为此表单上有图片等。

用户窗体运行的代码。

Private Sub ComboBox1_DropButtonClick()

'Determines the controller model based off selection
If ComboBox1.Text = "VHX-6000 + VHX-A60E" Then
    Controller = 6000
Else
    Controller = 950
End If

'Updates textbox1 with current pricing info
TextBox1.Text = Application.VLookup(Controller, Sheet3.Range("A37:C45"), 2, 0)   

End Sub

Private Sub Continue1_Click()

price = 0

'Determines if it should show the camera page based on the controller selection
If Controller = 6000 Then
    CameraForm.Show
Else
    Camera = 6020
    StageForm.Show
End If

End Sub

Private Sub Image6_BeforeDragOver(ByVal Cancel As MSForms.ReturnBoolean, ByVal Data As MSForms.DataObject, ByVal X As Single, ByVal Y As Single, ByVal DragState As MSForms.fmDragState, ByVal Effect As MSForms.ReturnEffect, ByVal Shift As Integer)

End Sub

Private Sub Label2_Click()

End Sub

Private Sub UserForm_Activate()

'Make Sheet 3 activate to avoid that weird error message towards the end
Worksheets("sheet3").Activate

'Sets the dropdown list
ComboBox1.List() = Sheet3.Range("C6:C7").Value

'Clears the quote information if present
Sheet3.Range("M51:O100").ClearContents

Controller = 0

End Sub

Private Sub UserForm_Click()

End Sub

Private Sub UserForm_Initialize()

'Full Screen
With Me
    .Width = Application.Width
    .Height = Application.Height
End With

End Sub

【问题讨论】:

  • 嗯,听起来您对表单的递归调用在某处打开。在它崩溃之前你不会看到它,因为你已经绑定了消息泵线程。
  • 您是否获得了Application.WidthApplication.Height 的合理值?如果您的图像是自动缩放的,并且它们是 MAX_INT,那么可以做到。
  • @Comintern 尝试删除重新调整它的部分,但仍然出现相同的错误:/
  • @RobertHarvey 你能详细说明一下吗?很抱歉,我有点不合群,并且一直在自学所有这些。感谢您的帮助,只是不完全理解您的建议。
  • 你知道什么是递归吗?

标签: excel vba out-of-memory


【解决方案1】:

感谢这是一个旧线程,但我遇到了类似的问题,这让我头痛了几个小时。

我一直在研究双显示器并设置了六个用户表单

如果我随后尝试在未连接任何显示器的情况下在笔记本电脑上打开一些用户表单,我会遇到戏剧性的“灾难性故障”。

我发现问题与显示设置中的屏幕比例有关。我的显示器是 100%,我的笔记本电脑是 125%。

当我将笔记本电脑更改为 100% 时……瞧。所有工作。老实说有点愚蠢,但认为值得一提

【讨论】:

  • 谢谢这解决了这个问题..真的很奇怪的问题,需要报告给微软..
【解决方案2】:

谜题

没什么可继续的:

为了加载表单,我在 Sheet3 代码窗口中有一个命令按钮 OLE 对象的代码:

Private Sub CommandButton1_Click()
  Load ControllerForm
  ControllerForm.Show
End Sub

请注意与您的代码的两个不同之处:

Sub Button1_Click()
  ControllerForm.Show
End Sub
  1. 您是否需要使用Load ControllerForm
  2. 这些按钮之间存在区别:Commandbutton1 和 Button1。您的 Button1 是 msoFormControl (8),而我的按钮是 msoOLEControlObject(12)。 看here

【讨论】:

    猜你喜欢
    • 2010-12-04
    • 2016-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多