Check if specified Excel workbook is already open, with .vbs

Continuing from the title... If it is already open, make it the active window before continuing with script. And if it's not already open, simply open it and continue with script. I have become very confused trying to get this procedure
to happen, this mish-mash is what I have so far:
path=createobject("scripting.filesystemobject").getparentfoldername(wscript.scriptfullname)
excelpath=path&"\example.xlsx"
set objword = createobject("word.application")
set coltasks = objword.tasks
i = 0
for each objtask in coltasks
    name = lcase(objtask.name)
    If instr(name, "example.xlsx") then
        i=1
    end if
next
 if i=1 then
     wscript.echo "An active instance of example.xlsx has been found"
     objexcel.visible=true
 call CODE
 else
     set objexcel=createobject("excel.application")
     objexcel.workbooks.open(excelpath)
     set objsheet=objexcel.activeworkbook.worksheets(1)
     objexcel.visible=true 
     call CODE
 end if
sub CODE
    objword.quit
    wscript.echo "Place rest of code here"
end sub
A running instance of the "example.xlsx" is never detected and made the active window, so the first if block never executes. It always opens a new instance of "example.xlsx". What am I doing wrong? ...I'm a novice at this
so an explanation is appreciated, and if there's an easier way, that too is appreciated.

Spot on, changed the first if condition it to:
if i=1 then
 wscript.echo "An active instance of example.xlsx has been found"
 set objexcel=getobject(excelpath)
 call CODE
...and hey presto, thanks jrv! :D ...By the way, barring the poor indentation and lowercase syntax, is this code a passable attempt at achieving this, or is there a simpler way? And if there's another file named "example" which is not
an excel file, in the task manager running applications list, will it affect the outcome? - Should I add "microsoft excel" to the instr search? 

Similar Messages

Maybe you are looking for

  • HT203175 only a tiny operation screen opens when I start Itunes in Windows Vista

    In Windows Vista I am unable to open iTunes (updated 10.7);  all that comes up is a small window in top left hand corner which enables me to press start.  There is nothing else.  It used to work well a few months ago but I downloaded a whole series,

  • BIOS Update taking too long

    I come across that the tablet/pc needes a BIOS Update which automatically began. But that was at 6pm(Puerto Rico Time) and its 10:43pm and its still going. I can not do anything else on the tablet/pc. I bought the tablet/pc online. I got it at the be

  • DB13 error: permission denied

    hi all, We want to take backup of our Production server through DB13. but when we start backup it generate error " 11/2/2010     1:15:13 PM     Job started 11/2/2010     1:15:13 PM     Step 001 started (program RSDBAJOB, variant &0000000000010, user

  • Random seed for the grain in lightroom?

    Is it possible to get a random seed for the grain in lightroom when applying to multiple images? I really like the grain in lightroom and would like to use it for an image sequence, so its really important that the grain changes from frame to frame.

  • Taking a web role instance offline

    We ran into a mission-critical problem when one of the three web role instances became unresponsive while maintaining the appearance of a healthy instance with the Azure Load Balancer, causing traffic getting directed there and creating an outage. We