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

Loop thru task manager 1

Status
Not open for further replies.

GShen

MIS
Sep 26, 2002
561
US
I have an application where I delete WORD an EXCEL documents in specific folders to get ready for the up coming week. If a document is locked because there was some error on that pc, I cannot delete any of the documents. Is there a way to loop through all the applications in task manager and then delete them (winword.exe and excel.exc) ? I really would not care if the user is in the middle of using them or not. I really need to get those documents deleted or else I end up printing this same documents the following week.

Please let me know if you need more information.

Thanks,

Remember when... everything worked and there was a reason for it?
 
I'd use the GetObject function.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV,
I am a little green here.
What do I do with it ? Where can I find the parameters to use with it? It is asking for a path and a class.
If I can find a way to unlock the member that would work also. I figured if I can end the task, that would work also. I don't want to purchase software to do UNLOCK it, which is the only way I found so far.
Thanks,

Remember when... everything worked and there was a reason for it?
 
A starting point:
Code:
On Error Resume Next
Set xl = GetObject(, "Excel.Application")
If Err.Number = 0 Then
  xl.DisplayAlerts = False
  xl.Quit
End If
Err.Clear

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Back again after playing with this. Here is where I am at.

I do a getobject for excel and a quit. The display alerts tto false didn't seem to anything.

When doing this for WORD, the quit needed the following.

x1.quit SaveChanges:=wdDoNotSaveChanges

Again, the display alerts didn't matter.

So far so good.

The problem is my error code never gets set. I want to put this in a tight loop. Close everything down and then my other loop which runs will delete all the files.

When I test err.number in the intermediate pane I get
Object Variable or With Block variable not set.

Any ideas ?

I wanted to do something like
Do While err.number <> 0
set WordObj = GetObject(, "word.application")
WordObj.quit SaveChanges:=wdDoNotSaveChanges
loop

Do While err.number <> 0
set ExcelObj = GetObject(, "excel.application")
ExcelObj.quit
loop


Remember when... everything worked and there was a reason for it?
 
On Error Resume Next
Do While Err.Number = 0
Set WordObj = GetObject(, "word.application")
WordObj.Quit SaveChanges:=0 ' wdDoNotSaveChanges
Set WordObj = Nothing
Loop
Err.Clear
Do While Err.Number = 0
Set ExcelObj = GetObject(, "excel.application")
ExcelObj.Quit
Set ExcelObj = Nothing
Loop

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV,
I found the problem.
I have Err defined as
Dim Err As ADODB.error

I just took out my Dim statement for Err. It now works.
I am able to reference Err.clear as well. It would not allow me to do this before.

I also see you set the Obj for Word And Excel to nothing in the loops. Should this be done in the loop or outside the loop after it is finished ?

Remember when... everything worked and there was a reason for it?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top