简体   繁体   中英

vba excel userform won't show

Morning all!

I'm having trouble getting a userfrom to show.

Below is the code I want to use. I declare the Userfrom (oUserform) as a public variable, initialize it and make the changes, then show it.

That's the plan anyway, however I get an error with oUserform.show, saying that the object doesn't support the property or method.

    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

Any ideas?

You'll want to declare oUserform as an instance of frmbusinessimpact and use the New keyword.

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

The book Professional Excel Development has a good chapter on how, and why, to code userforms this way. I've got a more specific example at http://yoursumbuddy.com/a-flexible-vba-chooser-form/ .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM