none
Can not GetObject Excel 2016 RRS feed

  • Question

  • Sorry because my trouble there was much on the forum, but I can not find a good solution for it.

    I created a Ribbon, on my ribbon have two buttons. Corresponding to two buttons are two forms will appear when clicked.

    Each form will reference the Excel object via GetObject Method. Both of them use:

    Dim ExcelApp as Excel.Application

    ExcelApp = GetObject(,"Excel.Application")

    But only form1 work well.

    If I run form1 then run form2, there are no error.

    If I only run form2, I get trouble: "System.Exception: Cannot create ActiveX component."

    I don't understand why.

    • Edited by Hung Dau Saturday, April 21, 2018 3:13 PM
    Saturday, April 21, 2018 2:59 PM

All replies

  • Try the following with Set which is used before an object variable.

    Set ExcelApp = GetObject(,"Excel.Application")


    Regards, OssieMac

    Sunday, April 22, 2018 11:03 AM
  • thanks you. But I work with VB.NET so Set not supported anymore
    • Edited by Hung Dau Sunday, April 22, 2018 1:49 PM
    Sunday, April 22, 2018 1:49 PM
  • Hi Hung Dau,

    I try to make a test with your code, But it looks like you posted the incomplete code which is not able to reproduce the issue.

    I find that the code you had posted is working fine on my side.

    Code:

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim ExcelApp As Excel.Application
    
            ExcelApp = GetObject(, "Excel.Application")
            Me.Label1.Text = ExcelApp.ActiveWorkbook.Name
        End Sub


     Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim ExcelApp As Excel.Application
    
            ExcelApp = GetObject(, "Excel.Application")
            Me.Label1.Text = ExcelApp.ActiveWorkbook.Name
        End Sub

    Output:

    If issue still persist then I suggest you to post the full actual code.

    We will try to make a test with it and try to reproduce the issue.

    It will help us to narrow down the issue.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, April 23, 2018 5:42 AM
    Moderator
  • Hi Hung Dau,

    Is your issue solved?

    I find that you did not follow up this thread for a long time.

    If your issue is solved then I suggest you to post your solution and mark it as an answer.

    If your issue is still exist then try to refer the solution given by the community members.

    If then also you have any further questions then let us know about it.

    We will try to provide further suggestions to solve the issue.

    Thanks for your understanding.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, May 3, 2018 9:24 AM
    Moderator