I'm writing a program that writes information into an excel sheet and then saves it. This works fine and dandy when the excel sheet it closed but when it's open it wont let me save due to that it's already open and it's protected.
Here's the general code:
Dim MyExcel As New Excel.Application
Try
MyExcel.Workbooks.Open(ExcelFile.Text)
Catch
End Try
MyExcel.Range("A6").Activate()
MyExcel.ActiveCell.Value = "Hello"
MyExcel.Workbooks.Save()
MyExcel.Workbooks.Close()
I was thinking maybe finding out whether the file was open and in that case close then reopen it after the save is complete?
I'm not sure what the best solution is and how to pull it off.
Thanks
Stephen
Here's the general code:
Dim MyExcel As New Excel.Application
Try
MyExcel.Workbooks.Open(ExcelFile.Text)
Catch
End Try
MyExcel.Range("A6").Activate()
MyExcel.ActiveCell.Value = "Hello"
MyExcel.Workbooks.Save()
MyExcel.Workbooks.Close()
I was thinking maybe finding out whether the file was open and in that case close then reopen it after the save is complete?
I'm not sure what the best solution is and how to pull it off.
Thanks
Stephen