在初始化时关闭表单会引发错误 [英] Closing a form on initialize throws error

查看:62
本文介绍了在初始化时关闭表单会引发错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制定用于更新特定工作表的标准化流程.除了我给他们的功能外,我不希望有任何用户控制.为此,我锁定了工作表,然后使用某些宏加载了表格.一种形式是设计用来从工作表中删除数据的.它在编写和测试时都可以正常工作,但是我尝试对其进行更新,以便如果您在不删除任何相关数据的情况下打开它,它会弹出一个对话框,然后使用卸载我"来关闭表单.这将关闭表单,但是excel会引发错误:

I'm trying to make a standardized process for updating a particular worksheet. I want no user control except for the functions I give them. To do that I have locked sheets and then forms that load with certain macros. One form is designed to remove data from the sheet. It works fine as written and tested, but I've tried to update it so that if you open it without any relevant data to remove, it spits out a dialogue box and then uses Unload Me to close the form. This closes the form but then excel throws an error:

运行时错误'91':对象变量或未设置块变量

Run-time error '91': Object variable or With block variable not set

从只有一行的模块中加载表单:

The form is loaded from a module that only has the one line:

MyForm.Show

这是excel引发错误的地方.在初始化表格时,组合框将根据工作表中的数据填充值.如果加载后组合框为空,则该表单应该引发对话框,然后关闭.

This is where excel is throwing the error from. On initialization of the form, a combobox is filled with values based on the data in the sheet. If the combobox is empty after loading, the form is supposed to throw the dialogue box and then close.

If ComboBox.ListCount = 0 Then
    MsgBox "No Data"
    Unload Me
End If

如何在不使模块引发错误的情况下进行负载检查?

How can I perform the check on load without having the error thrown from the Module?

推荐答案

这实际上无法回答您的问题.但是我建议的是在实际加载表单之前检查模块代码.像这样:

This doesn't actually answer your question. But what I suggest is do the checking in your module code before you actually load the form. Something like:

Sub LoadForm()
    If Sheets("Sheet1").Range("A1") = "" Then '<~~ your condition here
        MsgBox "No Data"
    Else
        MyForm.Show
    End If
End Sub

这篇关于在初始化时关闭表单会引发错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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