PC Review


Reply
Thread Tools Rate Thread

Detect if an excel file is open

 
 
=?Utf-8?B?SkNQ?=
Guest
Posts: n/a
 
      1st Sep 2007
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 With Quote
 
 
 
 
Guest
Posts: n/a
 
      1st Sep 2007
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" <(E-Mail Removed)> wrote in message
news:5151C7FD-7011-467B-A274-(E-Mail Removed)...
> 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 With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
detect if a file is open deerchao Microsoft C# .NET 1 17th Sep 2007 10:25 AM
Detect if an Excel file is open =?Utf-8?B?SmFrb2IgTGl0aG5lcg==?= Microsoft Dot NET Framework 2 6th Nov 2006 07:26 AM
Re: Detect A File Is Open Ken Snell Microsoft Access Form Coding 7 11th Nov 2003 12:05 AM
Re: Detect A File Is Open Michel Walsh Microsoft Access Form Coding 1 7th Nov 2003 02:54 PM
Detect if file is open Chad Microsoft Excel Programming 4 9th Jul 2003 05:05 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:43 AM.