Message 1 of 3
Test if an Excel file is open

Not applicable
12-08-2008
03:42 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to write a function that checks if an Excel workbook is open (read only or not), and if it’s open assign a variable to it.
I have found many examples of how to test if an Excel workbook is open from excel VBA, but can’t get it to work in AutoCad VBA. Any help in getting this code to work in Autocad would be appreciated.
This is the Testing function I have so far:
Function WorkbookOpen(WorkBookName As String) As Boolean
' returns TRUE if the workbook is open
WorkbookOpen = False
Dim Wbk As Workbook
'On Error GoTo WorkBookNotOpen
If Len(Excel.Application.Workbooks(WorkBookName).Name) > 0 Then
MsgBox "WorkbookOpen = True", , "Testing MsgBox"
WorkbookOpen = True
Exit Function
End If
MsgBox "WorkbookOpen = False", , "Testing MsgBox"
WorkBookNotOpen:
End Function
Thanks,
Kai
I have found many examples of how to test if an Excel workbook is open from excel VBA, but can’t get it to work in AutoCad VBA. Any help in getting this code to work in Autocad would be appreciated.
This is the Testing function I have so far:
Function WorkbookOpen(WorkBookName As String) As Boolean
' returns TRUE if the workbook is open
WorkbookOpen = False
Dim Wbk As Workbook
'On Error GoTo WorkBookNotOpen
If Len(Excel.Application.Workbooks(WorkBookName).Name) > 0 Then
MsgBox "WorkbookOpen = True", , "Testing MsgBox"
WorkbookOpen = True
Exit Function
End If
MsgBox "WorkbookOpen = False", , "Testing MsgBox"
WorkBookNotOpen:
End Function
Thanks,
Kai