在 Windows 10 Excel 2013 上删除命名范围时出错 - 旧版本工作正常

Error Deleting Named Range on Windows 10 Excel 2013 - Older Versions Work Fine

我遇到了一个我真的不知道如何解决的问题。我有一个在 Windows 7 Excel 2010 中完美运行的代码,并且一直如此。在过去的几周里,它出现了一个错误,但只有当 运行 in Windows 10 Excel 2013.

基本上,下面的代码将一些数据表复制到一个新的工作簿中,以便删除 VBA(因为这被公司过滤器阻止了)。然后循环遍历所有对象和名称并在通过 Outlook 发送之前删除它们

Private Sub btnSend_Click()
'---------------------Create the email spreadsheet---------------------------------
Dim FName           As String
Dim FPath           As String
Dim NewBook         As Workbook
Dim EEName As String
Dim nm As Name

EEName = Range("ForeNameCell").Value & " " & Range("SurnameCell").Value
FPath = VBA.Environ("temp") & "\" 'file path to store the copy of the sheet
FName = "NS Form - " & EEName & " " & VBA.Format(VBA.Now(), "mm_dd_yyyy hh mm AMPM")

Set NewBook = Workbooks.Add 'create a new workbook
ThisWorkbook.Sheets("contract Print Out").Copy Before:=NewBook.Sheets(1) 'copy over the printoutallfields sheet
ThisWorkbook.Sheets("Oracle Data").Copy Before:=NewBook.Sheets(1) 'copy over the printoutallfields sheet
'copy and paste special data in new workbook to remove formula
NewBook.Sheets("contract Print Out").Cells.Copy
NewBook.Sheets("contract Print Out").Cells.PasteSpecial xlPasteValues
NewBook.Sheets("Oracle Data").Cells.Copy
NewBook.Sheets("Oracle Data").Cells.PasteSpecial xlPasteValues
'remove back buttons
Dim myshape As Shape
For Each myshape In NewBook.Sheets("contract Print Out").Shapes
    myshape.Delete
Next myshape
For Each myshape In NewBook.Sheets("Oracle Data").Shapes
    myshape.Delete
Next myshape
'remove links and named ranges
Application.Calculation = xlManual
On Error Resume Next
For Each nm In NewBook.Names
    nm.Delete ' This line now errors in W10 E2013
Next
On Error GoTo 0
Application.Calculation = xlCalculationAutomatic

'NewBook.Sheets("PrintOutallFields").Name = "User Data" 'rename it in the destination workbook
Application.DisplayAlerts = False 'turn off overwrite prompt so that it will just overwrite
NewBook.SaveAs Filename:=FPath & FName 'save the file
DoEvents
Application.DisplayAlerts = True 'turn overwrite prompt back on
NewBook.Close

出现的错误如下所示,当我查询它试图删除的名称时,出现了#NAME?。每个名字似乎都以这种方式出现在代码中,因为当我跳过并尝试转到下一个 nm 时,同样的事情发生了。

我忘了说我们从工作簿中删除名称的原因是因为它们总是引用原始文件。当我们收到它时,这会导致问题,因为原件当然会始终在客户的 PC 上。

我的猜测是 MS 在他们永恒的智慧中推送了一个更新,该更新在版本之间中断 VBA...再次!我已经不得不修复其中的一些,但我被这个难住了。

我的 Windows 个人资料似乎某处有问题。该文件还适用于办公室周围的其他 Windows 10 个装置。重新安装 Excel 没有解决它,但重建我的 Windows 配置文件可以。这对我来说是第一次,我以为我已经看到了一切。

我要感谢所有对此进行调查的人。我确定如果这是 Excel 的正常问题,枚举建议会很准确。