[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:
Dim objXLSheet As Object
Dim ExcelApp As excel.Application
Dim ExcelBook As excel.Workbook
Dim ExcelSheet As excel.Worksheets
Dim g_ExcelPath As String
g_ExcelPath = "C:\listamatforan\1_08A.xls"
strSheetName = "EXTENDED_PART_LIST"
Set ExcelApp = CreateObject("Excel.Application")
With ExcelApp
'.ExcelBook
.Workbooks.Open (g_ExcelPath)
' Set ExcelSheet = ExcelApp.Worksheets.Add
' Set ExcelSheet = ExcelApp.Sheets(1)
'With .ExcelSheet
If .Worksheets.Count = 1 Then
.Worksheets.Add.Name = "DELETE"
.Workbooks.Application.SaveWorkspace
End If
If .Worksheets.Count > 1 Then
For buc_sheets = 1 To .Worksheets.Count
den_sheet = Worksheets(buc_sheets).Name
If strSheetName = den_sheet Then
.Worksheets(strSheetName).Activate
.Worksheets(strSheetName).Delete
End If
Next
Workbooks.Close '(g_ExcelPath)
'Set .Workbooks.Application.ActiveSheet = Nothing
End If
'End With
End With
ExcelApp.Application.Quit
Set ExcelApp = Nothing
Re: [RESOLVED] Kill excel process
Ah yes, I'd forgotten about this - it's another one that shows a confirmation message.. unfortunatley you can't specify the option here, but you can temporarily disable confirmation messages (only temporarily tho, otherwise they wont be shown when the user does similar things).
Two lines of code need to be added like this:
VB Code:
ExcelApp.DisplayAlerts = False
.Worksheets(strSheetName).Delete
ExcelApp.DisplayAlerts = True
Re: [RESOLVED] Kill excel process
Thank you a 1.000.000. times more for your help. My best regards!
Quote:
Originally Posted by si_the_geek
Ah yes, I'd forgotten about this - it's another one that shows a confirmation message.. unfortunatley you can't specify the option here, but you can temporarily disable confirmation messages (only temporarily tho, otherwise they wont be shown when the user does similar things).
Two lines of code need to be added like this:
VB Code:
ExcelApp.DisplayAlerts = False
.Worksheets(strSheetName).Delete
ExcelApp.DisplayAlerts = True