Solved

How to track my Excel 2007 appliction is open.

Posted on 2013-05-13
2
280 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now