MR Campbell
Board Regular
- Joined
- Aug 2, 2002
- Messages
- 113
At the moment, there is no compile error or runtime error, but if I manually attempt to open the file (that was successfully read from), I get the message that the file is already open and is locked by myself (the user) and that multiple Excel processes are still running (I checked the task manager).
How do I close this Excel file (no changes to be made since I only read from the file) and quit Excel from running ?
Here is what I have at the moment :
Dim FirstName, Surname As String
'file path and name for the Excel file
Dim FileNamePath As String = "C:\Users\MRC\Desktop\MRC Files\Visual Basic Files\SwimManager 2014\CurrentSeasonDATA\SquadData.xls"
Dim xl As Excel.Application
Dim wb As Excel.Workbook
Dim sht As Excel.Worksheet
xl = New Excel.Application 'run a new Excel application
xl.Visible = False 'make Excel invisible
wb = xl.Workbooks.Open(FileNamePath) 'open the workbook file
sht = DirectCast(wb.Worksheets("DOB"), Excel.Worksheet) 'define the worksheet
FirstName = sht.Cells(6, 3).Value 'read the first name
Surname = sht.Cells(6, 4).Value 'read the surname
'Write the name to a textbox
TextBox2.Text = FirstName & " " & Surname
wb.Close(SaveChanges:=False, Filename:=FileNamePath) '<==== not sure about these lines from HERE
xl.Workbooks.Close()
xl.Quit()
wb = Nothing
sht = Nothing
xl = Nothing
How do I close this Excel file (no changes to be made since I only read from the file) and quit Excel from running ?
Here is what I have at the moment :
Dim FirstName, Surname As String
'file path and name for the Excel file
Dim FileNamePath As String = "C:\Users\MRC\Desktop\MRC Files\Visual Basic Files\SwimManager 2014\CurrentSeasonDATA\SquadData.xls"
Dim xl As Excel.Application
Dim wb As Excel.Workbook
Dim sht As Excel.Worksheet
xl = New Excel.Application 'run a new Excel application
xl.Visible = False 'make Excel invisible
wb = xl.Workbooks.Open(FileNamePath) 'open the workbook file
sht = DirectCast(wb.Worksheets("DOB"), Excel.Worksheet) 'define the worksheet
FirstName = sht.Cells(6, 3).Value 'read the first name
Surname = sht.Cells(6, 4).Value 'read the surname
'Write the name to a textbox
TextBox2.Text = FirstName & " " & Surname
wb.Close(SaveChanges:=False, Filename:=FileNamePath) '<==== not sure about these lines from HERE
xl.Workbooks.Close()
xl.Quit()
wb = Nothing
sht = Nothing
xl = Nothing