N
neotokyo
Anyone know how to do this function?
Basically, if a workbook is not opened yet, then open it.
If its already opened, then go to that window.
I got this from the web, but if the workbook is already opened, i
gives me an error :
Function WorkbookOpen(WorkBookName As String) As Boolean
'Returns TRUE if the workbook is open
Dim myxl As Excel.Application
On Error Resume Next
Set myxl = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
Err.Clear
WorkbookOpen = False
Else
WorkbookOpen = True
End If
Set myxl = Nothing
End Function
How I call the function :
Dim strSourceFilename As String
strSourceFilename = Range("A1").Text
If Not WorkbookOpen(strSourceFilename) = False Then
Application.Workbooks.Open FileName:=strSourceFilename
End If
Thanks for any help
Basically, if a workbook is not opened yet, then open it.
If its already opened, then go to that window.
I got this from the web, but if the workbook is already opened, i
gives me an error :
Function WorkbookOpen(WorkBookName As String) As Boolean
'Returns TRUE if the workbook is open
Dim myxl As Excel.Application
On Error Resume Next
Set myxl = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
Err.Clear
WorkbookOpen = False
Else
WorkbookOpen = True
End If
Set myxl = Nothing
End Function
How I call the function :
Dim strSourceFilename As String
strSourceFilename = Range("A1").Text
If Not WorkbookOpen(strSourceFilename) = False Then
Application.Workbooks.Open FileName:=strSourceFilename
End If
Thanks for any help