excel saving

SDZ98

New member
Joined
Jun 12, 2012
Messages
3
Programming Experience
Beginner
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
 
Er ... isn't it always open on account of what you open it in Line 3? And would it not always be closed at the time of saving if you swapped lines 8 and 9?
 
Back
Top