Consulting

Results 1 to 4 of 4

Thread: calculation state

  1. #1
    VBAX Mentor
    Joined
    Jun 2005
    Posts
    374
    Location

    calculation state

    hello
    i am trying to let excel tell me what calculation mode is currentlly active.
    please correct the following:
    [VBA]
    Sub caculatem()
    Dim x As String
    Dim ireply As VbMsgBoxResult
    If Application.Calculation = xlCalculationAutomatic Then Exit Sub
    MsgBox "calculation currentlly is manual,change to automatic?", vbYesNo + vbCritical, "calculation state"
    If ireply = vbYes Then
    Application.Calculation = xlCalculationAutomatic
    End If
    End Sub

    [/VBA]
    thanks
    moshe

  2. #2
    VBAX Contributor moa's Avatar
    Joined
    Nov 2006
    Posts
    177
    Location
    [vba]
    Sub caculatem()

    If Not Application.Calculation = xlCalculationAutomatic Then

    If MsgBox("calculation currentlly is manual,change to automatic?", _
    vbYesNo + vbCritical, "calculation state") = vbYes Then
    Application.Calculation = xlCalculationAutomatic
    End If

    End If

    End Sub
    [/vba]
    Glen

  3. #3
    Knowledge Base Approver
    The King of Overkill!
    VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    Hi moshe,

    If you don't care about the semiautomatic/manual difference, Glen's code would be perfect. If the difference matters, you could do something like [vba]Sub caculatem()
    Dim vCalc As String
    Select Case Application.Calculation
    Case xlCalculationAutomatic: Exit Sub
    Case xlCalculationManual: vCalc = "manual"
    Case xlCalculationSemiautomatic: vCalc = "automatic except for tables"
    End Select
    If MsgBox("Calculation currently is set to " & vCalc & ", change to fully " & _
    "automatic?", vbYesNo + vbCritical, "Calculation state") = vbYes Then _
    Application.Calculation = xlCalculationAutomatic
    End Sub[/vba]Matt

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I have a toolbar button that I use to toggle the calculaton mode and I set the tooltiptext to show me what it is currently

    [vba]

    Option Explicit
    Option Private Module

    Declare Function GetKeyState Lib "user32" (ByVal fnKey As Long) As Integer

    Const vkShift As Integer = &H10

    Private Sub SetCalculateMode() 'Shifted is automatic, unshifted is manual
    Dim sMode As String
    Dim nState As Long

    If GetKeyState(vkShift) < 0 Then
    Application.Calculation = xlAutomatic
    sMode = "Automatic"
    nState = msoButtonDown
    Else
    Application.Calculation = xlManual
    sMode = "Manual"
    nState = msoButtonUp
    End If
    With Application.CommandBars.ActionControl
    .TooltipText = "Calculation mode is " & sMode
    .State = nState
    End With

    End Sub
    [/vba]
    Last edited by Bob Phillips; 04-05-2007 at 11:45 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •