我打开文件时Excel(2007)函数不计算(自动计算)

时间:2013-10-30 12:23:44

标签: excel vba

我已经通过vba创建了一个函数,我已经使用这个函数来创建一个迭代表。我已经将工作簿计算设置为自动,并且一切正常但是当我打开excel文件时,包含上述函数的单元格给出了#name错误,每次我需要重新计算。有办法解决这个问题吗?

Public Function FrictionFactor(relativeroughness, reynoldsnumber)

    'Dim relativeroughness, reynoldsnumber As Double
    fNext = 0.005               ' initial value for f
    fIncrement = 0.005          ' initial step size
    Convergence = 0.000001      ' sets the decimal place accuracy of the result

    Do

        fStart = fNext
        LHSColebrookStart = 1 / (fStart ^ 0.5)
        RHSColebrookStart = -2 * (Log((relativeroughness / 3.7) + (2.51 / (reynoldsnumber * (fStart ^ 0.5)))) / Log(10))
        DifferenceStart = LHSColebrookStart - RHSColebrookStart

        fNext = fStart + fIncrement
        LHSColebrookNext = 1 / (fNext ^ 0.5)
        RHSColebrookNext = -2 * (Log((relativeroughness / 3.7) + (2.51 / (reynoldsnumber * (fNext ^ 0.5)))) / Log(10))
        DifferenceNext = LHSColebrookNext - RHSColebrookNext

        If DifferenceStart * DifferenceNext < 0 Then        ' march f in opposite direction and more slowly
            fIncrement = fIncrement / -10
        ElseIf DifferenceStart * DifferenceNext = 0 Then    ' done
            fIncrement = 0
        End If                                              ' keep marching f in same direction and at same rate

    Loop While Abs(fStart - fNext) > Convergence

    FrictionFactor = fStart
End Function

1 个答案:

答案 0 :(得分:0)

发生这种情况的通常原因是在打开工作簿时未启用宏。检查您的安全设置。