locked
GetObject in .NET Core RRS feed

Answers

  • Hi AntSalc,

    Thanks for your feedback.

    >>Is there not a plan to make Office.Interop compatible with .NET Core?

    You can report a problem in developer community forum for more efficient responses. 

    Besides, in order to solve the loading assembly error, try to make direct references to the Interop assemblies(Dependencies => COM =>add related Microsoft Interop assemblies =>set "Embed Interop Types" to "Yes" ).

    Best Regards,

    Xingyu Zhao  


    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.

    • Marked as answer by AntSalc Tuesday, June 23, 2020 4:50 PM
    Tuesday, June 23, 2020 2:03 AM

All replies

  • Hello,

    Would using early binding for working with Excel rather than late binding by a possibility? That looks like the best option for .NET Core.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Wednesday, June 17, 2020 1:49 PM
  • I rarely use late binding.

    How can I use GetObject with early binding anyway in .NET Core?

    Do you mean opening the workbook with methods like Workbooks.Open?

    If so, that is not the same at all.

    How can they leave aside such an important method?



    • Edited by AntSalc Wednesday, June 17, 2020 4:18 PM
    Wednesday, June 17, 2020 3:19 PM
  • I rarely use late binding.

    How can I use GetObject with early binding anyway in .NET Core?

    Do you mean opening the workbook with methods like Workbooks.Open?

    If so, that is not the same at all.

    How can they leave aside such an important method?



    For clarity perhaps show what code you have at this time so there is no confusion as the code samples on the link you provided are late binding and using VB6 style of coding not event conventional VB.NET  e.g.

    ' Test to see if a copy of Excel is already running.
    Private Sub testExcelRunning()
        On Error Resume Next
        ' GetObject called without the first argument returns a
        ' reference to an instance of the application. If the
        ' application is not already running, an error occurs.
        Dim excelObj As Object = GetObject(, "Excel.Application")
        If Err.Number = 0 Then
            MsgBox("Excel is running")
        Else
            MsgBox("Excel is not running")
        End If
        Err.Clear()
        excelObj = Nothing
    End Sub


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Wednesday, June 17, 2020 6:54 PM
  •         Dim ExcelApp As Application = Nothing
            Dim InvWorkbook As Workbook = Nothing

            Select Case Process.GetProcessesByName("EXCEL").Length

                Case 0

                    ExcelApp = CType(CreateObject("Excel.Application"), Application)
                    ExcelApp.Visible = True
             

                    InvWorkbook = ExcelApp.Workbooks.Open(PAdir + InvFile)

                Case 1

                    InvWorkbook = CType(GetObject(PAdir + InvFile), Workbook)
                    InvWorkbook.Windows(1).Visible = True
                    ExcelApp = InvWorkbook.Application


                Case Else

                    MsgBox("More than one Excel instance." + vbCrLf + "Reduce to one Excel instance and start again")
                    Exit Sub

            End Select
    • Edited by AntSalc Wednesday, June 17, 2020 9:24 PM
    Wednesday, June 17, 2020 9:19 PM
  • Doing the above without GetObject is more complicated

    Wednesday, June 17, 2020 9:21 PM
  • Hi AntSalc,

    Thanks for your feedback.

    As an alternative to 'GetObject' method, you can consider using Marshal.BindToMoniker(String) Method.

    As the document says: This method provides the same functionality as the GetObject method in Visual Basic 6.0 and Visual Basic 2005.

    Hope it could be helpful.

    Best Regards,

    Xingyu Zhao

     


    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.

    Friday, June 19, 2020 7:24 AM
  • Thank you Xingyu Zhao. It seems that Marshal.BindToMoniker(String) Method should work.

    However, I am having trouble with, I think, the string required to call the method.

    I get file not found error when I use the full path or just the file name of, for example, an Excel workbook


    • Edited by AntSalc Friday, June 19, 2020 6:50 PM
    Friday, June 19, 2020 6:49 PM
  • Have you considered enumerating the contents of the running object table to see what it contains?
    Friday, June 19, 2020 9:09 PM
  • My problem seems to be the Office reference.

    The error message is: Could not load file or assembly 'office, Version=15.0.0.0, 

    I don't easily find that .dll

    Why is it needed instead of the one I already have referenced, Version 16?

    Saturday, June 20, 2020 6:34 AM
  • Hi AntSalc,

    >>My problem seems to be the Office reference.

    The Interop NuGet packages are not compatible with .NET Core.

    Check the suggestions in following references:

    1. .NET core 3.0 and MS Office Interop
    2. Access to Office.Interop from .NET Core?

    Note: COM is a Windows technology and you cannot use it in other platforms.

    Best Regards,

    Xingyu Zhao


    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, June 22, 2020 7:20 AM
  • Hello Xyngyu,

    I have looked at your links.

    So it seems that there is no point in trying further .NET Core with Office.Interop

    Which seems like a big hole.

    Is there not a plan to make Office.Interop compatible with .NET Core?

    Thanks

    Monday, June 22, 2020 3:20 PM
  • Hi AntSalc,

    Thanks for your feedback.

    >>Is there not a plan to make Office.Interop compatible with .NET Core?

    You can report a problem in developer community forum for more efficient responses. 

    Besides, in order to solve the loading assembly error, try to make direct references to the Interop assemblies(Dependencies => COM =>add related Microsoft Interop assemblies =>set "Embed Interop Types" to "Yes" ).

    Best Regards,

    Xingyu Zhao  


    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.

    • Marked as answer by AntSalc Tuesday, June 23, 2020 4:50 PM
    Tuesday, June 23, 2020 2:03 AM
  • Xyngyu,

    set "Embed Interop Types" to "Yes" did it.

    I can now work with Excel using BindToMoniker 

    I will study the info at https://docs.microsoft.com/en-us/dotnet/standard/assembly/embed-types-visual-studio

    Many thanks.

    • Marked as answer by AntSalc Tuesday, June 23, 2020 4:50 PM
    • Unmarked as answer by AntSalc Tuesday, June 23, 2020 4:50 PM
    Tuesday, June 23, 2020 4:50 PM