saving excel file from VB.Net

shankar

Member
Joined
Dec 14, 2002
Messages
12
Hello,
I am trying to save some data in an excel file from my VB.Net application. But once saved and I try to open the excel file manually, the data is invisible.This happens if I try to open the file with my application running. But if I am close my application, I am able to see the data.
I found this in the documentation.

"When you are using Automation to edit an Excel workbook, keep the following in mind.
Creating a new instance of Excel and opening a workbook results in an invisible instance of Excel and a hidden instance of the workbook. Therefore, if you edit the workbook and save it, the workbook is saved as hidden. The next time the user opens Excel manually, the workbook is invisible and the user has to click Unhide on the Window menu to view the workbook.
To avoid this behavior, your Automation code should unhide the workbook before editing it and saving it. Note that this does not mean that Excel itself has to be visible."

What does this mean? has it got anything to do with the problem I am facing?

SHankar.
 
You could set Application.Visible = true. This would display the version of excel that your application is using.
 
Hmmm... the link that you are quoting seems to be here: Creating, Saving, Opening, and Closing Workbook Objects.

I have never seen such behaviour exhibited and kicking it around now, I cannot reproduce this... And yet you are having this very problem! The do provide the solution, however:
To avoid this behavior, your Automation code should unhide the workbook before editing it and saving it. Note that this does not mean that Excel itself has to be visible.
What they are saying is that you should use code similar to the following when you save your workbook:
Code:
MyWB.Windows(1).Visible = True
MyWB.Save
Or use .SaveAs or whatever you want, but make sure that your Workbook is not hidden when it is saved. As for making the Excel.Application itself Visible, this is not necessary. :)
 
Back
Top