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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check if excel file is open

Status
Not open for further replies.

mharcourt

Programmer
Apr 9, 2003
49
0
0
US
I need a little help in a vb script to determine if a specific excel file is already open.
Thanks
 
Can do a simple check like this. But an xls not in use by excel might be in use by other application. That is out of the scope of such check.
[tt]
xlsspec="d:\abc\xyz.xls" 'your input

if bxls_inuse(xslspec) then
wscript.echo "The xls file : " & xlsspec & " is in use."
else
wscript.echo "The (xls) file : " & xlsspec & " is not in use (by excel) if exists."
end if

function bxls_inuse(spath)
bxls_inuse=false
dim bexists : bexists=true
dim oxl
on error resume next
set oxl=getobject(,"excel.application")
if err.number<>0 then
err.clear
bexists=false
end if
on error goto 0
if bexists then
for each owkbk in oxl.workbooks
if lcase(owkbk.fullname)=lcase(spath) then
bxls_inuse=true
exit for
end if
next
end if
end function
[/tt]
 
Thanks. This is exactly what I need. The spreadsheet is not being accessed by other sources except a users.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top