导入文本文件并删除以范围名称开头的错误

我试图在Excel 2010中导入文本文件(其内容粘贴在这里)。

样品
0.000336179308182416 0.0003623072328649 0.000330580466347818 0.000328403140930966 0.000326536860231208 0.000316583362896417 0.000331824654826285 0.000376926431150615 0.000359196764802228 0.00035110955014428 0.000340222914920751 0.00038594678488213 0.000374438054920212 0.00038719097133022 0.000356708390252258 0.000355464204180755 0.000362307232454562 0.000408031102693052 0.00042793809249897 0.000361685139135481 =AVERAGE(B2:U2) =MEDIAN(B2:U2) =STDEV.P(B2:U2) 0.000317516503116533 0.000324670578360742 0.000343644429001611 0.00031720545739935 0.000316272316168398 0.000322182204319699 0.000319071737757159 =AVERAGE(B2:AE2) =MEDIAN(B2:AE2) =STDEV.P(B2:AE2)

导入工作正常。 在excel中打开文本文件后,我编写了以下VBA代码以删除以_开头的范围名称。

Private Sub Workbook_Open()
 For Each n In ActiveWorkbook.Names
  If Mid$(n.Name, 1, 1) = "_" Then
    MsgBox ("The file being deleted is " + n.Name)
     n.Delete
  End If
 Next n
End Sub

并保存该文件。 现在我再次打开这个保存的xlsm文件,并显示msg“正在删除的文件是_xlfn.STDEV.P”。

即使我在我的文本文件中指定了STDEV.P函数,但我不知道该范围名称是从哪里添加到ActiveWorkBook.Names集合中的。 随后的删除操作也会抛出一个错误,因为范围名称是一个excel函数名称。 请帮我解决这个问题。


以_xlfn开头的范围名称由excel创建,因此任何删除这些范围名称的尝试都会引发错误。 所以我避免了删除以_xlfn开头的范围名称。

For Each n In ActiveWorkbook.Names
    If Mid$(n.Name, 1, 5) = "_xlfn" Then
        continue
    Else  
        n.Delete
    End If
Next n
链接地址: http://www.djcxy.com/p/52345.html

上一篇: Error while importing a text file and deleting the Range name that start with

下一篇: openxml 2.5, how to insert a string into a cell?