PC Review


Reply
Thread Tools Rate Thread

change cpu used

 
 
Dan
Guest
Posts: n/a
 
      18th Feb 2008
How can I call the Windows API in VBA in order to programmatically set the
affinity used by Excel.
DAN
 
Reply With Quote
 
 
 
 
JLatham
Guest
Posts: n/a
 
      18th Feb 2008
This applies to Excel 2007 only. I've not tried/tested it under earlier
versions, plus the Tools/Options setting to turn it off is not available in
earlier versions.

I'm not certain you can set the affinity to a specific CPU, but you can
control multi-threading in Excel easily enough. (Although an API call to the
OS may be able to do so).

If you don't mind always running without Multithreaded recalc, then you can
'disable it in the Office Button->Excel Options->Advanced->Formulas settings.
'Note: This change may impact calculation times for other books.

Programmatically you can do this with code similar to the following:

Dim multiThreadCount As Long
Dim multiThreadMode As XlThreadMode
Dim multiThreadEnabled As Boolean
multiThreadEnabled = Application.MultiThreadedCalculation.Enabled
If (multiThreadEnabled) Then
multiThreadCount = Application.MultiThreadedCalculation.threadCount
multiThreadMode = Application.MultiThreadedCalculation.ThreadMode
End If
'Disable multithreading temporarily
Application.MultiThreadedCalculation.Enabled = False

'YOUR CODE HERE

'Restore the Multithreaded State
Application.MultiThreadedCalculation.Enabled = multiThreadEnabled
If (multiThreadEnabled) Then
Application.MultiThreadedCalculation.threadCount = multiThreadCount
Application.MultiThreadedCalculation.ThreadMode = multiThreadMode
End If

Presumably that would all be within a Sub or Function declaration. You
could probably even set it up within the Workbook_Open() and _BeforeClose()
events with the first part to turn it off in the _Open() and the portion to
restore it in the _BeforeClose() event handler.


"Dan" wrote:

> How can I call the Windows API in VBA in order to programmatically set the
> affinity used by Excel.
> DAN

 
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
Use date modified to change format & create filter to track change =?Utf-8?B?UEFS?= Microsoft Excel Worksheet Functions 0 15th Nov 2006 09:17 PM
Change conditional formatting to coloured alternate rows dependent on a change in date? StargateFan Microsoft Excel Programming 4 2nd Aug 2006 11:28 AM
how to change the value of Request.ServerVariables["HTTP_REFERER"] on the ser ver? if not possible is there some way to change it by sending back javascript to the client and having the client automaticaly do something to change the value o Daniel Microsoft Dot NET Framework 1 14th Jul 2005 03:24 PM
how to change the value of Request.ServerVariables["HTTP_REFERER"] on the ser ver? if not possible is there some way to change it by sending back javascript to the client and having the client automaticaly do something to change the value o Daniel Microsoft C# .NET 1 14th Jul 2005 02:12 PM
how to change the value of Request.ServerVariables["HTTP_REFERER"] on the ser ver? if not possible is there some way to change it by sending back javascript to the client and having the client automaticaly do something to change the value o Daniel Microsoft Dot NET 0 14th Jul 2005 10:02 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:47 PM.