Results 1 to 3 of 3

Thread: Find already open excel file and detect current cell position and write AutoCAD Line data in excel

  1. #1
    100 Club
    Join Date
    2011-08
    Location
    Vadodara, India
    Posts
    147
    Login to Give a bone
    0

    Default Find already open excel file and detect current cell position and write AutoCAD Line data in excel

    Hi,
    I am new to vb.net

    I have a certain lines in AutoCAD and want to its property in already open excel file, then find current position of cell, its position, and write all extracted data in Text box value in excel file.

    Code:

    Code:
    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
            Dim objExcel As Excel.Application = System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application")
            Dim objWorkBook As Excel.Workbook
            Dim shXL As Excel.Worksheet
            Dim sCelR, sCelC As Integer
            Dim totalWorkBooks As Integer = objExcel.Workbooks.Count
            'MsgBox(totalWorkBooks & "    is Number of Open Workbooks")
    
    
            Dim ActiveBookIndex As Integer = objExcel.ActiveWindow.Index
            'MsgBox(ActiveBookIndex & "    is Active Window Index")
            'sCel = (objExcel.ActiveCell.Value & "   active cell")
            objWorkBook = objExcel.Workbooks(1)
            Dim FullName As String = objWorkBook.FullName
            'MsgBox(FullName & "    is FullName")
            Dim ObjWorkSheet As Excel.Worksheet = objWorkBook.Worksheets.Item(1)
            Dim OnlyName As String = objWorkBook.Name
            MsgBox(OnlyName)
            'MsgBox(ObjWorkSheet.Name)
            objExcel.ActiveWindow.Activate()
            sCelR = objExcel.ActiveCell.Row
            sCelC = objExcel.ActiveCell.Column
            shXL = objWorkBook.ActiveSheet
            'ObjWorkSheet.Range(sCelC & sCelR).Value = TextBox1.Text
            shXL.Range(sCelC & sCelR).Value = TextBox1.Text
            shXL.Range(sCelC & sCelR + 1).Value = TextBox2.Text
            shXL.Range(sCelC & sCelR + 2).Value = TextBox3.Text
        End Sub
    where I am wrong please help.
    Last edited by Opie; 2021-01-06 at 01:27 PM. Reason: [code] tags help readability of code

  2. #2
    100 Club
    Join Date
    2011-08
    Location
    Vadodara, India
    Posts
    147
    Login to Give a bone
    0

    Default Re: Find already open excel file and detect current cell position and write AutoCAD Line data in excel

    Hi!

    I have done solution for this code. but If excel application is not running it give error any idea.

    Code:
        Private Sub XlExport()
            Dim objExcel As Excel.Application = System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application")
            Dim objWorkBook As Excel.Workbook
            Dim sCelR, sCelC As Integer
            Dim totalWorkBooks As Integer = objExcel.Workbooks.Count
            Dim ActiveBookIndex As Integer = objExcel.ActiveWindow.Index
            objWorkBook = objExcel.Workbooks(1)
            Dim FullName As String = objWorkBook.FullName
            Dim ObjWorkSheet As Excel.Worksheet = objWorkBook.Worksheets.Item(1)
            Dim OnlyName As String = objWorkBook.Name
    
            objExcel.ActiveWindow.Activate()
            sCelR = objExcel.ActiveCell.Row
            sCelC = objExcel.ActiveCell.Column
            'MsgBox(sCelC & "     " & sCelR)
            objExcel.Cells(sCelR, sCelC).Value = TextBox1.Text
            objExcel.Cells(sCelR, sCelC + 1).Value = TextBox2.Text
            objExcel.Cells(sCelR, sCelC + 2).Value = ComboBox1.Text
            'worksheet.Range("A6").Activate()
            objExcel.Cells(sCelR + 1, sCelC).activate()
            objWorkBook.Save()
    any solution?
    Last edited by Opie; 2021-01-07 at 01:38 PM. Reason: [code] tags added

  3. #3
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,397
    Login to Give a bone
    0

    Default Re: Find already open excel file and detect current cell position and write AutoCAD Line data in excel

    You need to test for the condition where xl is not running. You do this using a Try..Catch statement. If you get an error trying to Get an instance of xl, then in the Catch statement, you use CreateObject() to create a new instance of xl.
    C:> ED WORKING....

Similar Threads

  1. Replies: 0
    Last Post: 2013-10-31, 08:42 PM
  2. find the start of a line that is already drawn
    By 3dway in forum AutoCAD General
    Replies: 6
    Last Post: 2008-07-10, 05:38 AM
  3. Moving from cell to cell
    By Grumpy in forum AutoCAD Tables
    Replies: 6
    Last Post: 2007-11-15, 10:31 PM
  4. Replies: 5
    Last Post: 2006-03-28, 07:27 PM
  5. get already open excel file
    By jcoon in forum VBA/COM Interop
    Replies: 2
    Last Post: 2004-08-22, 04:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •