Hi All,
Please let me know what happen? Error occurred when COM interop Autocad 2012 with excel 2010.
Thanks,
Hi,
what code does that message case?
What operating system and what office do you use (e.g. 64bit os ... and so 64bit AutoCAD and maybe 32bit Office)?
And the content of the message (the text under details) might also be necessary, so copy the whole text into a text-file and upload it here.
- alfred -
Yes. My computer use 64bit AutoCAD 2012-English SP2 and 32bit Excel V14.
This is full detail:
---------------------
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.Runtime.InteropServices.COMException (0x80004023): Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80004023 A Microsoft Software Installer error was encountered. (Exception from HRESULT: 0x80004023).
at System.Runtime.Remoting.RemotingServices.AllocateUninitializedObject(RuntimeType objectType)
at System.Runtime.Remoting.Activation.ActivationServices.CreateInstance(RuntimeType serverType)
at System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(RuntimeType serverType, Object[] props, Boolean bNewObj)
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at Color_tool.Module1.GetExcelData()
at Color_tool.Color_tool.MyCommand.Link_Excel_Copy()
at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorker(MethodInfo mi, Object commandObject, Boolean bLispFunction)
at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorkerWithExceptionFilter(MethodInfo mi, Object commandObject, Boolean bLispFunction)
at Autodesk.AutoCAD.Runtime.PerDocumentCommandClass.Invoke(MethodInfo mi, Boolean bLispFunction)
at Autodesk.AutoCAD.Runtime.CommandClass.CommandThunk.Invoke()
************** Loaded Assemblies **************
Hi,
and what is the code-snippet that brings up that exception?
And have you tried/looked at that: >>>click<<<? (as this is the message within your report)
- alfred -
Hi,
>> I still don't know how to solve my problem.
Maybe someone is able to do that, but for me: I need to look at the code-snippet to (hopefully) see what's wrong.
Without a code-line knowing what you are doing wrong is quite hard, don't you think so?
- alfred -
I'm sorry for misunderstanding your idea.
OK. Attachment is all my code.
Thanks,
Try this code, change to your suit before
'' Working example Imports System.IO Imports System.Reflection Imports System.Runtime.InteropServices Imports System.Globalization Imports System.Threading Imports Microsoft.Office.Interop.Excel Imports Excel = Microsoft.Office.Interop.Excel '' References -> COM -> Microsoft.Excel XX.0 Object Library ''' <summary> ''' Export one-dimensional array to Excel column ''' </summary> ''' <param name="sender"></param> ''' <param name="e"></param> ''' <remarks></remarks> Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim oldCult = CultureInfo.CurrentCulture() '' This line is very important! Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US") '<-- change culture on whatever you need Dim miss As Object = Type.Missing 'System.Reflection.Missing.Value Dim i As Integer Dim textfile As String = "C:\Test\MyCodes.txt" If (Not File.Exists(textfile)) Then MessageBox.Show("File does not exists") Return End If '' Open Excel Dim m_objExcel As Excel.Application = New Excel.Application m_objExcel.Visible = True m_objExcel.UserControl = True Dim m_objBooks As Excel.Workbooks = CType(m_objExcel.Workbooks, Excel.Workbooks) Dim m_objBook As Excel.Workbook = Nothing Try '' Open workbook m_objBooks.Open("C:\Test\Invoices.xlsx", False, False, miss, "", miss, miss, Excel.XlPlatform.xlWindows, miss, miss, miss, miss, miss, miss, miss) m_objBook = m_objExcel.ActiveWorkbook m_objBook.Activate() 'optional Dim m_objSheets As Sheets = m_objBook.Sheets Dim m_objSheet As Worksheet = m_objSheets.Item(1) '<--"Sheet1" m_objSheet.Cells.ClearContents() 'optional may to remove this line Dim m_objCells As Range = m_objSheet.Cells Dim m_objRange As Range = Nothing If IO.File.Exists(textfile) Then 'Create a StreamReader and open our text file Using pars As New StreamReader(textfile) i = 1 'Now add our columns (we will check to make sure the column doesnt exist before adding it) While Not pars.EndOfStream Dim line As String = pars.ReadLine '' write data starting from cell "A1" m_objRange = m_objSheet.Range(m_objCells(i, 1), m_objCells(i, 1)) m_objRange.NumberFormat = "@" m_objRange.Value2 = line i += 1 End While End Using End If '' optional just for debug only m_objSheet.Range(m_objCells(1, 1), m_objCells(i - 1, 1)).Select() m_objRange = m_objSheet.Range(m_objCells(1, 1), m_objCells(i - 1, 1)) m_objRange.BorderAround(Excel.XlLineStyle.xlContinuous, _ Excel.XlBorderWeight.xlMedium, Excel.XlColorIndex.xlColorIndexAutomatic, Excel.XlColorIndex.xlColorIndexAutomatic) m_objSheet.Columns.AutoFit() '' Save the file in the typical workbook format m_objBook.SaveAs("C:\Test\numbers.xlsx", Excel.XlFileFormat.xlWorkbookDefault, "", "", False, False, XlSaveAsAccessMode.xlNoChange, miss, miss, miss, miss, miss) Catch ex As System.Exception MessageBox.Show(ex.Message & vbCrLf & ex.StackTrace) Finally '' close workbook and quit Excel If Not m_objBook Is Nothing Then m_objBook.Close(False, miss, miss) m_objBook = Nothing End If m_objExcel.Quit() '' release process if it's still active System.Runtime.InteropServices.Marshal.FinalReleaseComObject(m_objExcel) Thread.CurrentThread.CurrentCulture = oldCult End Try End Sub
Hi Hallex,
All data transfer to excel successfully, however There's a message "Object reference not set to an instance an object.".
Please let me know what happen.
Thanks,