Object Required Error

poopiebear

New Member
Joined
Nov 19, 2010
Messages
41
I am attempting to do the following: Import 5 UserForms, then show UserForm2 when clicking the CommandButton.

UserForm2 will show if I have already have the user forms in my project, but when I import them, I get this object required error.

Code:
[COLOR=black][FONT=Verdana]Private Sub CommandButton1_Click()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Verdana]<o:p> </o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Verdana]'Import UserForms for data entry
Application.VBE.ActiveVBProject.VBComponents.Import "C:\UserForm2.frm"
Application.VBE.ActiveVBProject.VBComponents.Import "C:\UserForm3.frm"
Application.VBE.ActiveVBProject.VBComponents.Import "C:\UserForm4.frm"
Application.VBE.ActiveVBProject.VBComponents.Import "C:\UserForm5.frm"
Application.VBE.ActiveVBProject.VBComponents.Import "C:\UserForm6.frm"<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Verdana]<o:p> </o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Verdana]'Surname
If TextBox8.Text <> "" Then
    Sheet5.Range("D8") = TextBox8.Text
Else
    Sheet5.Range("D8") = ""
End If<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Verdana] <o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Verdana]'First Name
If TextBox9.Text <> "" Then
    Sheet5.Range("D9") = TextBox9.Text
Else
    Sheet5.Range("D9") = ""
End If<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Verdana] <o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Verdana]'Bunch of other stuff here....<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Verdana]<o:p> </o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Verdana]'Display UserForm<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Verdana]UserForm2.Show  <o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Verdana]<o:p> </o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Verdana]End Sub<o:p></o:p>[/FONT][/COLOR]

Thanks for the help!
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
What if you create the subroutine as separate for showing userform2 then call it as part of the routine at the end will that work?
 
Upvote 0
I'm exploring that option now, but I still get an error on the last line. Something like this??

Code:
Dim FileName As String
Dim VBForm As Object
Dim VBProj As Object
 
FileName = "C:\UserForm2.frm"
 
Set VBProj = Application.VBE.ActiveVBProject
Set VBForm = VBProj.VBComponents.Import(FileName)
 
VBA.UserForms.Add VBForm.Name
UserForms(0).Show
 
Upvote 0
I think I got it. The last 2 lines should be written this way instead:

Code:
VBA.UserForms.Add(VBForm.Name).Show

Thanks!
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top