Results 1 to 4 of 4

Thread: How to check with vb.net whether excel file is open

  1. #1
    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.

  2. #2
    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.

  3. #3
    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

  4. #4
    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.

Similar Threads

  1. How To Open .ods File in MS Excel?
    By Aagman in forum Windows Software
    Replies: 7
    Last Post: 10-02-2012, 09:06 AM
  2. Excel 2007 file fails to get permission to open in Excel 2011
    By Raju Chacha in forum Windows Software
    Replies: 6
    Last Post: 13-01-2012, 09:17 PM
  3. Replies: 4
    Last Post: 13-02-2011, 10:37 AM
  4. Open an Excel file from VB6
    By hatred in forum Windows Software
    Replies: 2
    Last Post: 26-03-2009, 01:30 PM
  5. Pdf file open in Excel
    By Clemens in forum Windows Software
    Replies: 3
    Last Post: 06-02-2009, 07:40 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,894,624.53238 seconds with 17 queries