2016-12-27 113 views
5

我有一個xls excel文件(excel 97-2003工作簿),其中有vba代碼。 我想將其轉換爲2007或更高版本的Excel,並啓用此vba代碼。 我曾嘗試:將excel 2003轉換爲2007或使用VBA最近的版本

  1. 另存爲宏觀enabled.xlsm文件
  2. this博客改變了宏的設置。 它改變了.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的屏幕截圖: enter image description here

+3

幫助我們hep你,**發佈失敗的代碼。** –

+0

@ Gary的學生請檢查,我上傳了代碼。 –

+1

哪一個失敗,在哪裏?他們是否正常運行,但只是返回'#Name'錯誤?你在你的單元格中放置了一個函數嗎?哪一個? – BruceWayne

回答

1

入住VB編輯器 - >工具 - >參考,如果有遺漏對開始選擇任何庫: enter image description here

如果是,則取消選擇它,然後再試一次。

0

如果要在工作表中調用代碼,則需要將代碼放在「ThisWorkbook」中。

相關問題