Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 10-08-2009
Member
 
Join Date: Feb 2009
Posts: 66
How to check with vb.net whether excel file is open

Some time it happens that Excel sheet remains open, I heard that we can manage this through code, so please tell me know how do I include code so that it checks if the workbook is open already or closed, if it is closed, then it is simply return the message that "file is closed". Also what control do I use to store a file path on a windows form so that at run time it runs that file.
Reply With Quote
  #2  
Old 10-08-2009
Member
 
Join Date: Jan 2006
Posts: 211
Re: How to check with vb.net whether excel file is open

Instead of Excel.Workbooks(name of workbook) try using Excel.Windows.Item(name of workbook). Check if that is nothing. The part that I used to determine if the file is open, I found somewhere on the web, I'll have to determine where later, and Edit this to include that info. If it's nothing, the workbook is not open, otherwise it'll return a collection of methods and properties, such as the index of the workbook.
Reply With Quote
  #3  
Old 10-08-2009
Member
 
Join Date: Dec 2008
Posts: 183
Re: How to check with vb.net whether excel file is open

Here's some code that I put together, I found somewhere on the web, You need to use error handling and the GtObject in combination with CreateObject in case its not open it will get created. I'll have to determine where later, and Edit this to include that info.

Private Sub Command1_Click()
Dim xl As New Excel.Application
Dim wb As Excel.Workbook
Set xl = New Excel.Application
Set wb = xl.Workbooks.Open("G:\\JOBLIST\JOBLIST.xls")
On Error Resume Next
wb.Activate
If Err = 0 Then MsgBox "Workbook is Open" Else "Workbook is Closed"
End Sub
Reply With Quote
  #4  
Old 10-08-2009
Member
 
Join Date: Oct 2008
Posts: 167
Re: How to check with vb.net whether excel file is open

First you may need to iterate through all the processes running in the memory to check whether at all if excel is running. If its open, then give a message that "excel_filename.xls is already open. Creating file excel_filename.xls"
Generate file excel_filename.xls". If its not open, no message required. Create file "excel_filename.xls". to avoid receiving a prompt that the file already existed, but I'm not sure how the file seems to be being created and named by the Filename variable, before the "oWB.SaveAs Filename" command.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to check with vb.net whether excel file is open"
Thread Thread Starter Forum Replies Last Post
How To Open .ods File in MS Excel? Aagman Windows Software 7 10-02-2012 09:06 AM
Excel 2007 file fails to get permission to open in Excel 2011 Raju Chacha Windows Software 6 13-01-2012 09:17 PM
Configuring Internet Explorer 8 to open Excel file in to Microsoft Excel Aaghaz Technology & Internet 4 13-02-2011 10:37 AM
Open an Excel file from VB6 hatred Windows Software 2 26-03-2009 01:30 PM
Pdf file open in Excel Clemens Windows Software 3 06-02-2009 07:40 AM


All times are GMT +5.5. The time now is 05:43 PM.