使用VBA将Excel 2003转换为2007或更高版本

5
我有一个xls格式的Excel文件(Excel 97-2003工作簿),其中包含VBA代码。 我想将其转换为2007或更新版本的Excel,并使其支持此VBA代码。 我尝试过以下方法:
  1. 另存为“宏启用的.xlsm”文件
  2. 更改宏设置,参考这篇博客。 这样做会将文档转换为.xlsm格式,但是在执行宏的单元格值上显示#NAME而不是值。 原始文件截图: enter image description here

转换后的结果如下: enter image description here 我现在陷入困境。

宏代码如下:

1.moveAcross.bas

    Attribute VB_Name = "MoveAcross"
Sub GoToValues()
Attribute GoToValues.VB_Description = "Macro recorded 23-01-2001 by Murad Assaggaf"
Attribute GoToValues.VB_ProcData.VB_Invoke_Func = " \n14"
'
' GoToValues Macro
' Macro recorded 23-01-2001 by Murad Assaggaf
'

'
    ActiveWindow.SmallScroll ToRight:=13
    ActiveWindow.LargeScroll Down:=-2
    ActiveWindow.SmallScroll Down:=-3
    ActiveWindow.SmallScroll ToRight:=2
    Range("X6").Select
End Sub
Sub ReturnToProfileArea()
Attribute ReturnToProfileArea.VB_Description = "Macro recorded 23-01-2001 by Murad Assaggaf"
Attribute ReturnToProfileArea.VB_ProcData.VB_Invoke_Func = " \n14"
'
' ReturnToProfileArea Macro
' Macro recorded 23-01-2001 by Murad Assaggaf
'

'
    Range("G5").Select
End Sub

2.Demand.bas

Attribute VB_Name = "Demand"
Function Demand(m0, m1, m2, m3, m4, m5, m6, EndInv, ST, Fraction)
    Static months(7) As Variant

    months(0) = m0
    months(1) = m1
    months(2) = m2
    months(3) = m3
    months(4) = m4
    months(5) = m5
    months(6) = m6

    Dim summy
    summy = 0

    If Fraction > 0 Then
        summy = months(ST + 1) * Fraction
    End If

    For n = 0 To ST
        summy = summy + months(n)
    Next n

    Demand = summy - EndInv

    If Demand < 0 Then
        Demand = 0
    End If
    End Function

3.Coverage.bas

Attribute VB_Name = "Coverage"
Function Coverage(m0, m1, m2, m3, m4, m5, m6, EndInv, ST, Fraction)

    Static months(7) As Variant

    months(0) = m0
    months(1) = m1
    months(2) = m2
    months(3) = m3
    months(4) = m4
    months(5) = m5
    months(6) = m6

    Dim summy
    summy = 0

    If Fraction > 0 Then
        summy = months(ST) * Fraction
    End If

    For n = 0 To (ST - 1)
        summy = summy + months(n)
    Next n

    Coverage = EndInv / (summy / (ST + Fraction))

End Function

编辑后的VBA截图: 输入图片说明


3
帮助我们来帮助您,发布导致错误的代码 - Gary's Student
@Gary'sStudent 请检查,我已上传代码。 - Noman Ahmad
1
哪一个失败了?在哪里失败了?它们是否正常运行但只返回“#名称”错误?您是否将其中一个函数放在该单元格中?是哪一个? - BruceWayne
这些 #NAME? 单元格是工作簿中的公式还是宏的结果? - gemmo
1
请在VB编辑器-->工具-->引用中检查是否选择了以[MISSING]或类似的方式开始的任何库?如果是,请取消选择,然后再试一次。 - Rufus
显示剩余10条评论
2个回答

1
请在VB编辑器中检查-->工具-->引用,是否选择了任何以MISSING开头的库: enter image description here 如果是,则取消选择并重试。

0

如果你想在工作表中调用代码,你需要将它放在“ThisWorkbook”中。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接