Gregorys05
Board Regular
- Joined
- Sep 24, 2008
- Messages
- 217
Hi all,
i have the below code that work great first time through, but if you go to run a second time it errors in various places each time.
If i debug and close excel manually and re run, it works fine again.
I believe excel is still running in the processes, is there a way to not only close the application but to all so kill the process.
Thanks
i have the below code that work great first time through, but if you go to run a second time it errors in various places each time.
If i debug and close excel manually and re run, it works fine again.
I believe excel is still running in the processes, is there a way to not only close the application but to all so kill the process.
Thanks
Code:
Set xlApp = CreateObject("Excel.Application")
xlApp.Workbooks.Open myFileName, True, False
xlApp.Application.ScreenUpdating = False
xlApp.Visible = True
With xlApp
Dim LastRow As Long
With ActiveSheet
LastRow = .Range("A1").SpecialCells(xlCellTypeLastCell).Row
End With
Range("D2:D" & LastRow).NumberFormat = "0"
For Each cell In Range("D2:D" & LastRow)
Test = cell.Value
If cell.Value = "" Then
cell.FormulaR1C1 = "=R[-1]C"
Else
End If
Next cell
End With
xlApp.Application.ScreenUpdating = True
xlApp.ActiveWorkbook.Close (True)
xlApp.Quit
Set xlApp = Nothing