Workbook Access – Open WorkBook
Opens an Excel workbook in the specified Excel.Application instance, or returns a reference if it is already open.
If the workbook is already open in the given Excel application (based on file name match), it is returned without reopening. If the file is not open and a valid path is provided, it is opened with Local:=True . If an error occurs during the process, the function returns Nothing.
VB
Public Function xlOpenWorkBook(CallingApp As Excel.Application,
FileName As String) As Excel.Workbook
Try
'Open Data Workbook
If Not xlIsExcelFileOpened(CallingApp, Path.GetFileName(FileName)) Then
If FileName <> "" Then
Return CallingApp.Workbooks.Open(FileName, Local:=True)
End If
Else
Return CallingApp.Workbooks(Path.GetFileName(FileName))
End If
Catch ex As Exception
End Try
Return Nothing
End Function