Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Detect if an excel file is open

I'm working with automation. I have two questions

1. How can detect if excel is running?
2. How can detect is a specific excel file (test.xls) is open? I is open,
the code should be close the file without save.

Thanks
jcp
--
Jose
  #2   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Detect if an excel file is open

This will close test.xls if it's open in Excel. However, since Excel can
have several instances running simultaneously, this is not smart enough to
know which one to look in. It assumes there is only 1 instance running. Does
that matter to you?

Sub CloseAWorkbook()
Dim xl As Object
Dim wkb As Object
On Error Resume Next
Set xl = GetObject(, "Excel.Application")
On Error GoTo 0
If Not xl Is Nothing Then
For Each wkb In xl.workbooks
If wkb.Name = "test.xls" Then
wkb.Close False
End If
Next
End If
Set wkb = Nothing
Set xl = Nothing
End Sub


"JCP" wrote in message
...
I'm working with automation. I have two questions

1. How can detect if excel is running?
2. How can detect is a specific excel file (test.xls) is open? I is open,
the code should be close the file without save.

Thanks
jcp
--
Jose



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
Detect open-state of xls from outside Excel Waterloo Excel Discussion (Misc queries) 2 May 6th 09 10:01 AM
Detect macros in an Excel file Gleam Excel Programming 17 March 21st 07 10:13 PM
automatically detect excel file in designated directory and convert to pdf brucelim80[_13_] Excel Programming 0 May 29th 06 03:04 AM
how to detect if user has a dialogbox open Von Shean Excel Programming 2 January 12th 04 02:35 PM
Detect if file is open Chad[_6_] Excel Programming 4 July 9th 03 05:05 AM


All times are GMT +1. The time now is 05:32 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"