Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Run-time error 424 using Application.VBE.ActiveVBProject.VBComponen

  Asked By: Colleen    Date: Jan 22    Category: MS Office    Views: 2558
  

I get the above 'object required' error when I use the above component
import method. The code is below:



Sub ImportForm(ThisForm, ShowIt, IsImported)
'loads form. shows form if ShowIt=TRUE
Dim WhichKey As String
'
'FYI ThisForm As String, ShowIt and IsImported As Boolean
'

IsImported = False 'default
'pref file open to get values to fill in form?
Call IsFileOpen(UserPref_fname, IsOpen)
If Not IsOpen Then
WhichKey = "UserPref"
Call RestoreGlobalFileName(WhichKey, Restored, FName)
If Not Restored Then Exit Sub
End If
ThisWorkbook.Activate
ChDir ThisWorkbook.Path
'already imported?
If Not VBComponentLoaded(ThisForm) Then
'does it exist?
If IsFileInPath(ThisForm & ".frm") Then
Application.VBE.ActiveVBProject.VBComponents.Import _
(ThisForm & ".frm")
IsImported = True
Else
IsImported = False
UserErrorNum = 6 & "*" & ThisForm & ".frm"
Call UserErrors(UserErrorNum)
Exit Sub
End If
Else
IsImported = True
End If
If ShowIt Then VBA.UserForms.Add(ThisForm).Show
End Sub



The macro stops after
Application.VBE.ActiveVBProject.VBComponents.Import , giving the
run-time error. The form is nonetheless imported. The system is
Windows98 and Xl97

There appears to be a lot of info on this topic, but as far as I can
tell, I've got the correct code for importing the component.

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Helene Stewart     Answered On: Jan 22

I get the above 'object required' error  when I use the above component
import method. The code is below:



Sub ImportForm(ThisForm, ShowIt, IsImported)
'loads form. shows form if ShowIt=TRUE
Dim WhichKey As String
'
'FYI ThisForm As String, ShowIt and IsImported As Boolean
'

IsImported = False 'default
'pref file open to get values to fill in form?
Call IsFileOpen(UserPref_fname, IsOpen)
If Not IsOpen Then
WhichKey = "UserPref"
Call RestoreGlobalFileName(WhichKey, Restored, FName)
If Not Restored Then Exit Sub
End If
ThisWorkbook.Activate
ChDir ThisWorkbook.Path
'already imported?
If Not VBComponentLoaded(ThisForm) Then
'does it exist?
If IsFileInPath(ThisForm & ".frm") Then
Application.VBE.ActiveVBProject.VBComponents.Import _
(ThisForm & ".frm")
IsImported = True
Else
IsImported = False
UserErrorNum = 6 & "*" & ThisForm & ".frm"
Call UserErrors(UserErrorNum)
Exit Sub
End If
Else
IsImported = True
End If
If ShowIt Then VBA.UserForms.Add(ThisForm).Show
End Sub



The macro stops after
Application.VBE.ActiveVBProject.VBComponents.Import , giving the
run-time error. The form is nonetheless imported. The system is
Windows98 and Xl97

There appears to be a lot of info on this topic, but as far as I can
tell, I've got the correct code for importing the component.

 
Answer #2    Answered By: Feodora Bonkob     Answered On: Jan 22

It didn't work, but I did locate
the problem. It appears that I'd sent you (and perhaps others) down
the wrong track - sorry. The 'object required' error  was with the
show method. The show method needs to be

VBA.UserForms.Add(ThisForm).Show

rather than ThisForm.Show. The later method only seems to work with
the Application.VBE.ActiveVBProject.VBComponents.Import method if it's
in a Sub Called from the Sub containing the import method - not the
other way around or not if the two are in the same Sub.

When the macro stopped after incurring the run-time  error, no debug
option was available; the only choice was to End the macro. It turns
out that when this occured and I went into VBE to look to see what was
going on, the 'view' that would appear was wherever I was prior to
running the macro, not where the problem was. Since I was editing the
module containing that Import code, I assumed incorrectly that the
error occurred in that module.

I still need to figure out why the imported form behaves differently
than if it were not imported...

 




Tagged: