Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check excel open

Status
Not open for further replies.

alifyag

MIS
Apr 15, 2002
18
US
Hello,
I use the following code to open a new instance of excel and do the needful

Set EXLApp = New Excel.Application
Set EXLApp = GetObject("", "excel.application")
EXLApp.Application.Workbooks.Open "C:\Perl\bin\test.xls"
EXLApp.Application.Visible = False
Set Sheet1 = EXLApp.Application.Workbooks(1).Worksheets("test")

However if my "test.xls" is already open by the user before the above code is run...i want to prompt the user to close it and save the necessary changes he made....how do i do that.
thanks in advance
al
 
check out faq222-3383

but the basics are: -

Private Function IsExcelAppOpen() As Boolean

On Error Resume Next

'Try first to use an existing instance.
Set myExcelApplication = GetObject(, "Excel.Application")

If Err = 429 Then
'Excel isn't running, so start it.
IsExcelAppOpen = False
Err.Clear
Else
'Excel is running
Set myExcelApplication = Nothing
IsExcelAppOpen = True
End If

End Function


If somethings hard to do, its not worth doing - Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top