Quantcast
Channel: MicroStation Programming Forum - Recent Threads
Viewing all articles
Browse latest Browse all 7260

Properly close excel file after reading it in VBA

$
0
0

How should I be closing an excel file that I have just read in VBA?  It is leaving an excel.exe process in the tasks after completing.

Sub SelectWorksheet()
   Dim oExcel As New Excel.Application
   Dim oWorkbook As Excel.Workbook
   Dim oWorksheet As Excel.Worksheet
   Dim i As Integer
   
      
   ActiveWorkspace.AddConfigurationVariable "TEMP_SHEET", 0
   Set oWorkbook = oExcel.Workbooks.Open(KeyinArguments)
   WS_Count = oWorkbook.Sheets.Count
   SelectWorksheetForm.ListBox1.Clear
   
   For i = 1 To WS_Count
        Set oWorksheet = ActiveWorkbook.Worksheets(i)
        SelectWorksheetForm.ListBox1.AddItem oWorksheet.Name
   Next i
    
   SelectWorksheetForm_Initialize
   
   Set oExcel = Nothing
   
End Sub

Viewing all articles
Browse latest Browse all 7260

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>