Opening and closing excel in VB6
I am trying to write a program which will open and close a spreadsheet. I am using the following code to do open the spreadsheet:
Code:
Dim xlapp As excel.Application
Dim xlstudentbook As excel.Workbook
Set xlapp = New excel.Application
Set xlstudentbook = xlapp.Workbooks.Open(App.Path & "\Students.xls")
To close the spreadsheet I am using this code:
Code:
Application.DisplayAlerts = False
xlstudentbook.Saved = True
xlstudentbook.Save
xlstudentbook.Close
Set xlstudentbook = Nothing
Set xlapp = Nothing
This all appears to work the first time the program closes the spreadsheet, however when the program closes it for the second time I still get a overwrite prompt.
How can I avoid this prompt and just save the spreadsheet with no questions asked?
Thanks in advance.
Re: Opening and closing excel in VB6
Welcome to VBForums :wave:
The way you open it is fine, but the way you close it is not quite right.. see the Excel Tutorial link in my signature for examples of the correct methods (in post #5).
If you still have problems after that, tell us the problem and show us your code (including the parts you didn't show before, as they can cause problems - even if they don't seem relevant).
Re: Opening and closing excel in VB6
Perfect, thanks very much.