![]() |
Using VB6.0, check if Excel / Specific Excel Programmes are 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 |
Using VB6.0, check if Excel / Specific Excel Programmes are 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 |
All times are GMT +1. The time now is 05:23 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com