RIAS
asked on
Check if excel is already open
Hello,
I n vb.net 2015 how to check if excel file is already open ?
Cheers
I n vb.net 2015 how to check if excel file is already open ?
Cheers
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks,
xlApp.Workbooks.get_Item ---error not a member of workbooks?
xlApp.Workbooks.get_Item ---error not a member of workbooks?
usually it can be get solved by cleaning and rebuilding the application
Private Shared Function IsWorkbookAlreadyOpen(app As Excel.Application, workbookName As String) As Boolean
Dim isAlreadyOpen As Boolean = True
Try
app.Workbooks.get_Item(wor
Catch theException As Exception
isAlreadyOpen = False
End Try
Return isAlreadyOpen
End Function
Then you can use it in your code like this:
Private Sub btnMinSummaryWorksheet_Cli
'This procedure runs when the btnOpenSummaryWorksheet button is clicked. Calls the
'Sub procedure opens the Summary Worksheet Dashboard
Dim xlApp As New Excel.Application
xlApp.Visible = True
Dim xlBook As Excel.Workbook
Dim workbookName = "F:\Test Environment\Compensation Workbook\Compensation Workbook\bin\Debug\2011.10
If IsWorkbookAlreadyOpen(xlAp
xlBook = xlApp.Workbooks.get_Item(w
Else
xlBook = xlApp.Workbooks.Open(workb
End If
Dim xlSheet As Excel.Worksheet
xlSheet = CType(xlBook.Sheets("Summa
xlSheet.Activate()
Me.Close()
End Sub