Solved

How to track my Excel 2007 appliction is open.

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

831 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