closing excel

Discussion in 'AutoCAD' started by Guest, Jan 19, 2004.

  1. Guest

    Guest Guest

    I'm trying to close excel after the code has run, but there is still an
    instance of excel open.

    Can anyone help?

    Thanks


    Private Sub cmdUpdate_Click()
    Dim objSet As AcadSelectionSet
    Dim objRef As AcadBlockReference
    Dim attribup As Variant
    Dim attribch As String
    Dim introw As Integer
    Dim tester As Integer

    If strFileName = "" Then
    MsgBox "No Spreadsheet selected.", vbExclamation
    Else
    On Error Resume Next
    ThisDrawing.SelectionSets("TEST").Delete 'Deletes selection set called
    "TEST" if it exist
    Err.Clear
    On Error GoTo 0
    Set objSet = ThisDrawing.SelectionSets.Add("TEST")

    Dim aryAttributeCode(0 To 3) As Integer
    Dim aryAttrubuteData(0 To 3) As Variant

    aryAttributeCode(0) = -4: aryAttrubuteData(0) = "<AND"
    aryAttributeCode(1) = 0: aryAttrubuteData(1) = "INSERT"
    aryAttributeCode(2) = 2: aryAttrubuteData(2) = "cable_tag"
    aryAttributeCode(3) = -4: aryAttrubuteData(3) = "AND>"
    'execute selection set
    objSet.Select acSelectionSetAll, , , aryAttributeCode, aryAttrubuteData

    Set objExcel = CreateObject("Excel.Application") 'Creates the Excel
    object
    Set CableLog = objExcel.Workbooks.Open(strFileName) 'Opens the correct
    spreadsheet
    Set objSheet = objExcel.ActiveWorkbook.Sheets("CABLE SCHEDULE A-B-C")

    For Each objRef In objSet

    attribup = objRef.GetAttributes

    introw = 4

    While attribch <> attribup(9).TextString
    ' While Not (IsEmpty(objSheet.Cells(introw, 11).Value))
    attribch = objSheet.Cells(introw, 11)

    Dim intcol As Integer
    Dim arrayloc As Integer

    intcol = 2
    arrayloc = 0

    If attribch = attribup(9).TextString Then
    While intcol <= 17
    objSheet.Cells(introw, intcol) =
    attribup(arrayloc).TextString
    intcol = intcol + 1
    arrayloc = arrayloc + 1
    Wend
    Else
    introw = introw + 1
    End If

    Wend

    Next objRef
    CableLog.Save
    CableLog.Close
    Set objSheet = Nothing
    Set CableLog = Nothing
    objExcel.Quit 'Closes Excel
    MsgBox " Spreadsheet has been updated"

    End If

    End Sub
     
    Guest, Jan 19, 2004
    #1
  2. Guest

    Ed Jobe Guest

    What about setting objExcel to Nothing?
     
    Ed Jobe, Jan 19, 2004
    #2
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.