Solved

How to track my Excel 2007 appliction is open.

Posted on 2013-05-13
2
282 Views
Last Modified: 2013-05-17
Hi, I am running vb.net application and open the excel file. Data are updated accordingly from vb.net to excel. I am managed this part.

I did use this function code to track my excel is open or not :-

Private Function TestEXCEL() as Boolean
dim fs as filestream
try
      fs = File.Open(xlpath, FileMode.Open, FileAccess.Read, FileShare.None)
     TestEXCEL = False
Catch ex as Exception
     TestEXCEL = True
End try

While after i do force close my excel file, my code try to reopen the file by coding i do face the error message as follows at this line

xlApp = New Excel.Application
xlworkbook = xlApp.Workbooks.Open(xlpath)   <-- Error pointed over here

Error message : COMException was unhandled
Excel cannnot open the file 'Tri_data.xlsx' because teh file format or file extension in not valid. Verif that the file has not been corrupted and that the file extension matches the format of the file.
0
Comment
Question by:TITO2009
2 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 39161029
What happens if you change

fs = File.Open(xlpath, FileMode.Open, FileAccess.Read, FileShare.None)

to

fs = File.Open(xlpath, FileMode.Open, FileAccess.Write,  FileShare.None)


Also add a

fs.Close

after the =False line.
0
 

Author Comment

by:TITO2009
ID: 39170305
Hi I am away from office, by tomorrow l am to cheek out and reply. sorry for delay .Thank you .
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question