我有以下(以前工作)的代碼,將公式轉換爲它們的常量值。我將它附加到電子表格上的表單按鈕上。它工作正常,然後決定休息。我點擊按鈕或運行宏,一個盒子出現「自動化錯誤」。 Excel幫助將其描述爲「自動化錯誤(錯誤440)」。
我遵循論壇的建議,在各個地方插入「On Error Resume Next」語句。我已經嘗試重新創建宏。我嘗試了一些不同版本的宏。但還沒有設法解決它。我如何擺脫這個錯誤?它是否類似於Java和Python中的try catch語句?VBA - 自動化錯誤 - Excel 2013
Sub RangeOfFormulasToConstants()
'
' Changes a selection of Formulas into their values thus removing the formula.
'
' Keyboard Shortcut: Ctrl+q
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "Useful box"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Application.ScreenUpdating = False
For Each Rng In WorkRng
Rng.Value = Rng.Text
Next
Application.ScreenUpdating = True
End Sub
我有其他的宏,目前與電子表格和表單按鈕工作。詳細如下。
Sub CopyFormulasNonCalculate()
'
' PasteMacro Macro
'
' Keyboard Shortcut: Ctrl+m
'
On Error Resume Next
Set Ret = Application.InputBox(Prompt:="Please select a range where you want to paste", Type:=8)
On Error GoTo 0
If Not Ret Is Nothing Then
Selection.Copy
Range("C2:F2").Copy Destination:=Ret
Application.CutCopyMode = False
End If
End Sub
Sub CopyFormulasCalculate()
Dim Ret As Range
Dim RangeToCopy As Range
Set RangeToCopy = Range("H3:AF3")
'
' PasteMacro Macro
'
' Keyboard Shortcut: Ctrl+m
'
Set Ret = Application.InputBox(Prompt:="Please select a range where you want to paste", Type:=8)
If Not Ret Is Nothing Then
RangeToCopy.Copy Destination:=Ret
Ret.Resize(1, RangeToCopy.Columns.Count).Calculate
Application.CutCopyMode = False
End If
End Sub
什麼行有錯誤? – 99moorem
Sub RangeOfFormulasToConstants() – AMorton1989
這根本沒什麼意義。 – AMorton1989