Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 158
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
can anyone tell me how to set excel to open to a specific folder bdc1952 Excel Discussion (Misc queries) 1 March 20th 08 05:14 PM
How can I insert a check box into a specific cell in Excel? Biggles Excel Discussion (Misc queries) 1 June 21st 07 12:05 PM
execl to check if another excel file is open... ohboy! Excel Programming 4 July 20th 05 03:41 AM
How to check for an open Network connection in Excel VBA? vrk1 Excel Programming 0 June 18th 05 02:58 AM
How to check Excel file already Open Rudy S Excel Programming 2 January 25th 05 02:00 PM


All times are GMT +1. The time now is 02:53 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"