Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 866
Default change cpu used

How can I call the Windows API in VBA in order to programmatically set the
affinity used by Excel.
DAN
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,365
Default change cpu used

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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change pivot source w/o refresh? Can't change original/copied pivo Toby Erkson[_5_] Excel Programming 4 July 16th 07 08:23 PM
Excel bar chart formatting of bars to change colors as data change JudyT Excel Discussion (Misc queries) 1 January 24th 07 06:07 PM
Use date modified to change format & create filter to track change PAR Excel Worksheet Functions 0 November 15th 06 09:17 PM
Change conditional formatting to coloured alternate rows dependent on a change in date? StargateFan[_3_] Excel Programming 4 August 2nd 06 11:28 AM
Change Cell from Validated List Not Firing Worksheet Change Event [email protected] Excel Programming 3 October 4th 04 03:00 AM


All times are GMT +1. The time now is 01:18 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"