早上好!
我无法让用户显示。
以下是我想要使用的代码。我将Userfrom(oUserform)声明为公共变量,初始化并进行更改,然后显示它。
无论如何,这是计划,但是我收到oUserform.show的错误,说该对象不支持该属性或方法。
Public oUserform As UserForm
Public iNumberOfRecords As Integer
Public iEndRow As Integer
Sub subIntialize()
Set oUserform = frmbusinessimpact
iEndRow = Sheet1.Cells(1, 1).CurrentRegion.Rows.Count
iNumberOfRecords = iEndRow - 1
Call subPopulateRecordClass(iEndRow)
With oUserform
.TotalRecords = iNumberOfRecords
.CurrentRecord = 1
Call subUpdateUserform
End With
oUserform.Show
End Sub
有什么想法吗?
答案 0 :(得分:1)
您需要将oUserform
声明为frmbusinessimpact
的实例并使用New
关键字。
Public oUserform As frmbusinessimpact
Public iNumberOfRecords As Integer
Public iEndRow As Integer
Sub subIntialize()
Set oUserform = New frmbusinessimpact
iEndRow = Sheet1.Cells(1, 1).CurrentRegion.Rows.Count
iNumberOfRecords = iEndRow - 1
Call subPopulateRecordClass(iEndRow)
With oUserform
.TotalRecords = iNumberOfRecords
.CurrentRecord = 1
Call subUpdateUserform
End With
oUserform.Show
End Sub
本书Professional Excel Development有一个很好的章节,说明如何以及为什么以这种方式对用户进行编码。我在http://yoursumbuddy.com/a-flexible-vba-chooser-form/有一个更具体的例子。