Using VB6.0, created an .exe file that fronts end access to programmes - VB6
used to gain ther functionality not available in Excel. Need to check if
specific Excel programmes are open to avoid attempting to re-open
Using VB6.0, created an .exe file that fronts end access to programmes - VB6
used to gain ther functionality not available in Excel. Need to check if
specific Excel programmes are open to avoid attempting to re-open
By <check if specific Excel programmes are open> do you mean check
whether specific workbooks (including AddIns) are open within an Excel
instance or do you just mean check for Excel instances?
In the below example the procedure Test, tries to open an Excel instance
using fcnOpenExcelInstance (you may want to change this so that it
doesn't open an instance if there isn't one already open).
Then Test passes the Excel instance to a function called
fcnCheckForOpenWorkbooks along with a string of the
workbook-to-be-checked's name which checks whether that workbook is
already open.
HTH,
Gareth
Sub Test()
Dim oXL as object
set oXL = fcnOpenExcelInstance
if oXL = nothing then
msgbox "couldn't open Excel"
end if
if fcnCheckForOpenWorkbooks (oXL, "Book1.xls")
msgbox "Book1.xls is open"
end if
End Sub
Function fcnCheckForOpenWorkbooks(XL as object, WBName as string) _
as boolean
Dim wb as object
for each wb in XL.workbooks
if lcase(wb.name) = lcase(WBname) then
'note, you might like to check against FullName rather than
'just name - that's why I'm using a loop here rather than
'something non-looping using error trapping
fcnCheckForOpenWorkbooks= true
end if
next wb
End Function
Function fcnOpenExcelInstance() as object
Dim oXL As Object
'get existing instance of Excel
On Error Resume Next
Set oXL = GetObject(, "Excel.Application")
On Error GoTo 0
'were we successful
If oXL Is Nothing Then
'create new instance
On Error Resume Next
Set oXL = CreateObject("Excel.Application")
On Error GoTo 0
End If
'check we were successful
If not oXL Is Nothing Then
'you might not need/want this line
oXL.Visible = True
set fcnOpenExcelInstance= oXL
End If
Set oXL = Nothing
End Function
Graham Masters wrote:
> Using VB6.0, created an .exe file that fronts end access to programmes - VB6
> used to gain ther functionality not available in Excel. Need to check if
> specific Excel programmes are open to avoid attempting to re-open
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks