Results 1 to 14 of 14

Thread: [RESOLVED] Kill excel process

Threaded View

  1. #1

    Thread Starter
    Addicted Member alexia_net's Avatar
    Join Date
    Jun 2006
    Posts
    216

    Resolved [RESOLVED] Kill excel process

    Hello! I am trying to delete a worksheet from an *.xls file and then create a different one with the same name. The thing is that excel hangs up during the for sequence. If I mark the For...Next sequence with ' then everything is ok. What is wrong? Please help me. I am desperate. Please check the code below:

    VB Code:
    1. Dim objXLSheet As Object
    2.   Dim ExcelApp As excel.Application
    3.   Dim ExcelBook As excel.Workbook
    4.   Dim ExcelSheet As excel.Worksheets
    5.  
    6.   Dim g_ExcelPath As String
    7.   g_ExcelPath = "C:\listamatforan\1_08A.xls"
    8.   strSheetName = "EXTENDED_PART_LIST"
    9.  
    10. Set ExcelApp = CreateObject("Excel.Application")
    11. With ExcelApp
    12.     '.ExcelBook
    13.     .Workbooks.Open (g_ExcelPath)
    14.    ' Set ExcelSheet = ExcelApp.Worksheets.Add
    15.    ' Set ExcelSheet = ExcelApp.Sheets(1)
    16.  
    17.      'With .ExcelSheet
    18.            If .Worksheets.Count = 1 Then
    19.                  .Worksheets.Add.Name = "DELETE"
    20.                  .Workbooks.Application.SaveWorkspace
    21.            End If
    22.  
    23.      
    24. If .Worksheets.Count > 1 Then
    25.     For buc_sheets = 1 To .Worksheets.Count
    26.         den_sheet = Worksheets(buc_sheets).Name
    27.             If strSheetName = den_sheet Then
    28.                     .Worksheets(strSheetName).Activate
    29.                     .Worksheets(strSheetName).Delete
    30.             End If
    31.     Next
    32.         Workbooks.Close '(g_ExcelPath)
    33.         'Set .Workbooks.Application.ActiveSheet = Nothing
    34. End If
    35.     'End With
    36. End With
    37.  
    38.  
    39. ExcelApp.Application.Quit
    40. Set ExcelApp = Nothing
    Last edited by si_the_geek; Jun 22nd, 2006 at 10:30 AM. Reason: added vbcode tags

Posting Permissions

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



Click Here to Expand Forum to Full Width