1

I'm writing a code to save the changes made to excel file using the button click option.

The code for that is very simple:

workbook.Save()         
workbook.Close()   
App.close()  - this is to close the Excel.Application

However, when I click the button I need to wait a bit and this image appears I would show the image but due to not having 10 reputation it doesn't let me, so I will explain.

The image form has the title File Now Available and below that in the description it said " 'test4.xlsx is not available for editing. Choose Read-Write to open it for editing "

When I click the cross top right of image the excel file opens and then I have to close that. Once done then I can read that file again.

Is there a way I can write a code whereby that image message doesn't appear and it closes the file properly, as I believe this code doesn't fully close it.

Any help is appreciated

Thank You

Satvir Singh
  • 59
  • 1
  • 9
  • The most likely reason for this error is not having properly disposed the Excel-interop objects and some of them are still running from a previous execution of your application. To confirm that this is the problem, press ctrl+alt+del and kill all the running Excel processes; your application should work fine now. Execute your code again (without killing anything) and confirm that the error is back. If you get this behaviour, the problem would surely be not properly disposing objects. Do some research and will find a solution quickly, there are lots of references about this issue. – varocarbas Aug 20 '15 at 09:30
  • Thank you for your suggestions. That was the issue now it seems to work fine. Also the close option works fine as well. Now I don't receive that image. I will see if there others that have this problem and try to get a solution to why this is happening. In the meantime if anyone knows why this might happen please let me and if I find something I will post that here – Satvir Singh Aug 20 '15 at 09:43
  • I told you why it is happening: because you are not disposing the objects properly. That is: these three lines you are including are not enough to release the resources associated with the workbook and App objects (= you are not completely closing the application). Here you have one of the (multiple) posts in SO showing how to properly account for this issue: http://stackoverflow.com/questions/158706/how-to-properly-clean-up-excel-interop-objects – varocarbas Aug 20 '15 at 09:47
  • I had a look at that but I have never used C# so I didn't fully understand what they saying about maybe if something in VB.net But thank you for the link that you provided – Satvir Singh Aug 20 '15 at 10:07
  • I know that it is C# (a language which is pretty similar to VB.NET; in fact, you should better understand the C# syntax as far as there are many more internet resources about C# than about VB.NET), it was a mere sample to help you understand my first comment: do some research and you will quickly find a solution. Ideally (= if you would have understood my first comment properly), I wouldn't have written the other two additional ones where I have provided some additional (and, in my opinion, completely unnecessary) information to help you understand my first comment. – varocarbas Aug 20 '15 at 10:17
  • 1
    I found it. Thank you for the help Anyone else asking similar question can refer to http://stackoverflow.com/questions/10309365/the-proper-way-to-dispose-excel-com-object-using-vb-net – Satvir Singh Aug 20 '15 at 10:22
  • 1
    See? It wasn't so difficult (I have even answered various questions on these lines myself in this VB.NET category). Now I can vote this post as a well-deserved duplicate. – varocarbas Aug 20 '15 at 10:25
  • 1
    @varocarbas... I would chill a bit... the guy is obviously new a has limited experience. Your comments that C# is similar to VB is your opinion but not that of many VB programmers. better to just point people in the direction of a C# to VB converter. – Mych Aug 20 '15 at 13:07
  • @Mych Thanks for the advice. In any case, I think that you have misunderstood my actions. Note that I have participated in this VB.NET category quite a lot (at a first sight, it seems that much more than you) and I haven't ever answered a VB.NET question with C# code (or vice versa); I have in fact criticised many people doing this kind of things. I was pretty clear in my first comment (independently upon your VB.NET knowledge): "these ideas + some work by your own = you would certainly find the solution". The OP continued expecting a perfect answer and I kept giving hints to find it. – varocarbas Aug 20 '15 at 13:51

0 Answers0