<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Get an already open active Excel workbook in AutoCad 2025 in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/get-an-already-open-active-excel-workbook-in-autocad-2025/m-p/13327059#M806</link>
    <description>&lt;P&gt;Thanks a lot _gile!&lt;/P&gt;&lt;P&gt;Shame on me, but I don't really understand the code - but I think I understand what it is doing and it is working fine.&lt;/P&gt;&lt;P&gt;Here is the code in Visual Basic:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;    &amp;lt;DllImport("ole32")&amp;gt;
    Private Shared Function CLSIDFromProgIDEx(&amp;lt;MarshalAs(UnmanagedType.LPWStr)&amp;gt; ByVal lpszProgID As String, &amp;lt;Out&amp;gt; ByRef lpclsid As Guid) As Integer
    End Function

    &amp;lt;DllImport("oleaut32")&amp;gt;
    Private Shared Function GetActiveObject(&amp;lt;MarshalAs(UnmanagedType.LPStruct)&amp;gt; ByVal rclsid As Guid, ByVal pvReserved As IntPtr, &amp;lt;Out&amp;gt; &amp;lt;MarshalAs(UnmanagedType.IUnknown)&amp;gt; ByRef ppunk As Object) As Integer
    End Function

    Public Shared Function GetActiveObject(ByVal progId As String, ByVal Optional throwOnError As Boolean = False) As Object
        If progId Is Nothing Then Throw New ArgumentNullException(NameOf(progId))
        Dim clsid = Nothing
        Dim hr = CLSIDFromProgIDEx(progId, clsid)

        If hr &amp;lt; 0 Then
            If throwOnError Then Marshal.ThrowExceptionForHR(hr)
            Return Nothing
        End If

        Dim obj As Object = Nothing
        hr = GetActiveObject(clsid, IntPtr.Zero, obj)

        If hr &amp;lt; 0 Then
            If throwOnError Then Marshal.ThrowExceptionForHR(hr)
            Return Nothing
        End If

        Return obj
    End Function&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 19 Feb 2025 06:18:33 GMT</pubDate>
    <dc:creator>Thomas.Oppen</dc:creator>
    <dc:date>2025-02-19T06:18:33Z</dc:date>
    <item>
      <title>Get an already open active Excel workbook in AutoCad 2025</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-an-already-open-active-excel-workbook-in-autocad-2025/m-p/13325471#M804</link>
      <description>&lt;P&gt;One of my .net plugins reads and writes data to an aleady open active Excel workbook.&lt;/P&gt;&lt;P&gt;To get the Excel sheet I'm using&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;Dim appXL As Excel.Application
Dim wbXL As Excel.Workbook
Dim shXL As Excel.Worksheet

appXL = GetObject(, "Excel.Application")
wbXL = appXL.ActiveWorkbook
shXL = appXL.ActiveSheet&lt;/LI-CODE&gt;&lt;P&gt;This has been working perfectly in AutoCad 2022 and 2023.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In AutoCAD 2025 GetObject(, "Excel.Application") doesn't deliver the application objetct anymore ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Up to now I rcognized that this might be related to AutoCad 2025 using .net 8.&lt;/P&gt;&lt;P&gt;I have tried&lt;/P&gt;&lt;P&gt;- GetObject("", "Excel.Application")&lt;/P&gt;&lt;P&gt;- Marshal.GetActiveObject("Excel.Application")&lt;/P&gt;&lt;P&gt;- DirectCast(Marshal.GetActiveObject("Excel.Application"), Excel.Application)&lt;/P&gt;&lt;P&gt;But to no avail ... all three are working in AutoCad 2023 but not in 2025.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you have any ideas for approaches on this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards&lt;/P&gt;&lt;P&gt;Thomas&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Feb 2025 13:00:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-an-already-open-active-excel-workbook-in-autocad-2025/m-p/13325471#M804</guid>
      <dc:creator>Thomas.Oppen</dc:creator>
      <dc:date>2025-02-18T13:00:26Z</dc:date>
    </item>
    <item>
      <title>Re: Get an already open active Excel workbook in AutoCad 2025</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-an-already-open-active-excel-workbook-in-autocad-2025/m-p/13326117#M805</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;You should read &lt;A href="https://blog.autodesk.io/autocad-2025-marshalgetactiveobject-net-core/" target="_blank" rel="noopener"&gt;this topic&lt;/A&gt;&amp;nbsp;(updated link).&lt;/P&gt;</description>
      <pubDate>Tue, 02 Dec 2025 12:58:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-an-already-open-active-excel-workbook-in-autocad-2025/m-p/13326117#M805</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2025-12-02T12:58:46Z</dc:date>
    </item>
    <item>
      <title>Re: Get an already open active Excel workbook in AutoCad 2025</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-an-already-open-active-excel-workbook-in-autocad-2025/m-p/13327059#M806</link>
      <description>&lt;P&gt;Thanks a lot _gile!&lt;/P&gt;&lt;P&gt;Shame on me, but I don't really understand the code - but I think I understand what it is doing and it is working fine.&lt;/P&gt;&lt;P&gt;Here is the code in Visual Basic:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;    &amp;lt;DllImport("ole32")&amp;gt;
    Private Shared Function CLSIDFromProgIDEx(&amp;lt;MarshalAs(UnmanagedType.LPWStr)&amp;gt; ByVal lpszProgID As String, &amp;lt;Out&amp;gt; ByRef lpclsid As Guid) As Integer
    End Function

    &amp;lt;DllImport("oleaut32")&amp;gt;
    Private Shared Function GetActiveObject(&amp;lt;MarshalAs(UnmanagedType.LPStruct)&amp;gt; ByVal rclsid As Guid, ByVal pvReserved As IntPtr, &amp;lt;Out&amp;gt; &amp;lt;MarshalAs(UnmanagedType.IUnknown)&amp;gt; ByRef ppunk As Object) As Integer
    End Function

    Public Shared Function GetActiveObject(ByVal progId As String, ByVal Optional throwOnError As Boolean = False) As Object
        If progId Is Nothing Then Throw New ArgumentNullException(NameOf(progId))
        Dim clsid = Nothing
        Dim hr = CLSIDFromProgIDEx(progId, clsid)

        If hr &amp;lt; 0 Then
            If throwOnError Then Marshal.ThrowExceptionForHR(hr)
            Return Nothing
        End If

        Dim obj As Object = Nothing
        hr = GetActiveObject(clsid, IntPtr.Zero, obj)

        If hr &amp;lt; 0 Then
            If throwOnError Then Marshal.ThrowExceptionForHR(hr)
            Return Nothing
        End If

        Return obj
    End Function&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2025 06:18:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-an-already-open-active-excel-workbook-in-autocad-2025/m-p/13327059#M806</guid>
      <dc:creator>Thomas.Oppen</dc:creator>
      <dc:date>2025-02-19T06:18:33Z</dc:date>
    </item>
    <item>
      <title>Re: Get an already open active Excel workbook in AutoCad 2025</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-an-already-open-active-excel-workbook-in-autocad-2025/m-p/13832637#M85834</link>
      <description>&lt;P&gt;Hi, I’m having the same problem with 2025, and the Typepad link doesn’t open. Could I get another reference to the solution?&lt;/P&gt;&lt;P&gt;My issue is that I cannot use any external library like OpenXML, ClosedXML, or EPPlus to read and write Excel files, even though they worked normally in earlier versions.&lt;/P&gt;&lt;P&gt;Many thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Oct 2025 11:06:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-an-already-open-active-excel-workbook-in-autocad-2025/m-p/13832637#M85834</guid>
      <dc:creator>alaammehrem</dc:creator>
      <dc:date>2025-10-01T11:06:04Z</dc:date>
    </item>
    <item>
      <title>Re: Get an already open active Excel workbook in AutoCad 2025</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-an-already-open-active-excel-workbook-in-autocad-2025/m-p/13928343#M86242</link>
      <description>&lt;P&gt;The topic was deteted &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Dec 2025 12:17:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-an-already-open-active-excel-workbook-in-autocad-2025/m-p/13928343#M86242</guid>
      <dc:creator>duykhaone</dc:creator>
      <dc:date>2025-12-02T12:17:56Z</dc:date>
    </item>
    <item>
      <title>Re: Get an already open active Excel workbook in AutoCad 2025</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-an-already-open-active-excel-workbook-in-autocad-2025/m-p/13928344#M86243</link>
      <description>&lt;P&gt;The topic was deleted, can you show me the code &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Dec 2025 12:20:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-an-already-open-active-excel-workbook-in-autocad-2025/m-p/13928344#M86243</guid>
      <dc:creator>duykhaone</dc:creator>
      <dc:date>2025-12-02T12:20:30Z</dc:date>
    </item>
    <item>
      <title>Re: Get an already open active Excel workbook in AutoCad 2025</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-an-already-open-active-excel-workbook-in-autocad-2025/m-p/13928415#M86244</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I updated the link in reply #2&lt;/P&gt;
&lt;P&gt;Here's the code:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;[DllImport("ole32")]
private static extern int CLSIDFromProgIDEx(
    [MarshalAs(UnmanagedType.LPWStr)] string lpszProgID, 
    out Guid lpclsid);

[DllImport("oleaut32")]
private static extern int GetActiveObject(
    [MarshalAs(UnmanagedType.LPStruct)] Guid rclsid,
    IntPtr pvReserved,
    [MarshalAs(UnmanagedType.IUnknown)] out object ppunk);

public static object? GetActiveObject(string progId, bool throwOnError = false)
{
    if (progId == null)
        throw new ArgumentNullException(nameof(progId));
    var hr = CLSIDFromProgIDEx(progId, out var clsid);
    if (hr &amp;lt; 0)
    {
        if (throwOnError)
            Marshal.ThrowExceptionForHR(hr);
        return null;
    }
    hr = GetActiveObject(clsid, IntPtr.Zero, out var obj);
    if (hr &amp;lt; 0)
    {
        if (throwOnError)
            Marshal.ThrowExceptionForHR(hr);
        return null;
    }
    return obj;
}&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 02 Dec 2025 13:05:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-an-already-open-active-excel-workbook-in-autocad-2025/m-p/13928415#M86244</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2025-12-02T13:05:23Z</dc:date>
    </item>
  </channel>
</rss>

