The following code is work in progress, but for now, it simply gets a list of excel files in a certain directory, loops thru those files and does a save as to another directory. The code works, but when I open the Windows Task Manager and monitor the Processes tab, I notice the following which concerns me.
As the code runs, I see that EXCEL.EXE opens and closes, but when the code finishes sometimes there are several instances of EXCEL.EXE process still lingering around. And thy never finish until I manually kill them. So that makes me think I'm not doing something properly to completely close out everything.
I hope you can understand what I am doing below and what my concern is. Thank you.
Imports System
Imports Microsoft.Office.Interop
Module Module1
Sub Main(ByVal Args() As String)
Dim MthYr As String = Args(0)
Dim SubDir As String = Args(1)
Dim FileList As String() = System.IO.Directory.GetFiles("C:\InsightExposures\" & MthYr & "\OriginalFormat\" & SubDir, "*.xls")
Dim FileName As String
Dim objExcel As Excel.Application
Dim objBook As Excel.Workbook
'Dim objSheet As Excel.Worksheet
Dim i As Integer
For i = LBound(FileList) To UBound(FileList)
FileName = Mid(FileList(i), FileList(i).LastIndexOf("\") + 2, Len(FileList(i)))
'MsgBox(FileList(i) & vbNewLine & FileName)
objExcel = New Excel.Application
objBook = CType(objExcel.Workbooks.Open(Filename:=FileList(i), ReadOnly:=True), Excel.Workbook)
objBook.SaveAs(Filename:="C:\InsightExposures\" & MthYr & "\ConvertedFormat\" & SubDir & "\" & FileName, FileFormat:=-4143)
objExcel.Quit()
Next i
End Sub
End Module

Sign In
Register
Help

MultiQuote




