Modify a process priority

P

pascalv

During some long VBA code execution, I would like to use other
applications.
To run these other applications in a comfortable way, I manually set
the Excel process to the lowest priority. But I would like to
automatically reduce the Excel application priority with some VBA code,
rather than doing it manually each time.

Is there any VBA code to modify a process priority?
I have Not found that in any field of the Application object

Thanks in advance if somebody has already done that

Pascal
 
S

Steve Yandl

Pascal,

If you're running on WinXP or Win2k, this can be done with WMI in a vbs
script. The script could be incorporated into a VBA routine but I've never
tested it in a situation where I would be changing the priority of the
process that the script was actually running from. I think I'd be inclined
to have two scripts with easy to find shortcuts to allow lowering Excel's
priority and to return it to normal.

To set priority to 'below normal' this would be the contents:

_ __ _ _ _ _ _ _ _ _ _ _ _ _ _

Const BELOW_NORMAL = 16384

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colProcesses = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'EXCEL.EXE'")
For Each objProcess in colProcesses
objProcess.SetPriority(BELOW_NORMAL)
Next

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _

If you really want the lowest priority, you would use
Const LOW = 64

To get back to normal, you would use
Const NORMAL = 32

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top