How to access the component of one project from another project(URGENT)

When the object of one project is accessed from some different project a run time error comes as follows:

“Object Variable or With block variable not set”

Sub DisProfile()

Dim obj As VBComponent
If ActiveSheet.Name = "Discount Profile" Then
    For Each obj In Workbooks("APTv3.2.xls").VBProject.VBComponents
        If obj.Name = "frmFlatDiscount" Then
            obj.Designer.Controls.Item("txtDiscount").text = "56"   ‘ Error comes here
            Exit For
        End If
    Worksheets("Discount Profile").ComboBox84.Value = Worksheets("Discount Profile").Range("A9")
End If
End Sub
Here I am trying to set text in the textBox of the form frmFlatDiscount
Who is Participating?
sgayatriConnect With a Mentor Commented:
Its because you have not added a reference from Project menu.
Add Project >> references >> yourvbcomponent

dim obj as new vbcomponent
or you must do this
I am giving an example here:
set obj=createobject("scripting.filesystemobject")

If you do this (the above line), no need to say 'new' etc.

which component are you trying to add?!?!
You must say
dim obj as new vbcomponent

dim obj as vbcomponent
set obj = new vbcomponent '' before using the object obj
By saying new you are actually creating an instance of the object called vbcomponent.

apoorva_srivAuthor Commented:
Thanks for the quick response

Now it is giving the error as "ActiveX component can't create object"
at the newly added line:
   set obj = new vbcomponent            ' error comes here
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.