VBA运行时错误1004:对象'_global'的方法'范围'

时间:2017-11-03 10:59:30

标签: vba excel-vba excel

我需要从文件wrongemails.csv中的文件list.xlsm中删除。

我有一个脚本:

Sub DelRows()
Dim ra As Range, delra As Range
Dim Arr() As Variant
    Application.ScreenUpdating = False    
    Arr = Range("[wrongemails.csv]wrongemails!$A$1:[wrongemails.csv]wrongemails!$A$4000")
     For Each ra In ActiveSheet.UsedRange.Rows
        For Each word In Arr
        If Not ra.Find(word, , xlValues, xlPart) Is Nothing Then            
           If delra Is Nothing Then Set delra = ra Else Set delra = Union(delra, ra)
        End If
        Next word
    Next
    If Not delra Is Nothing Then delra.EntireRow.Delete

End Sub

但是当我尝试使用它时,我有一个运行时错误1004:

**Method 'Range' of object'_global'** 

在行

Arr = Range("[wrongemails.csv]wrongemails!$A$1:[wrongemails.csv]wrongemails!$A$4000")

文件list.xlsm和wrongemails.csv位于同一文件夹中。

我的剧本出了什么问题?

1 个答案:

答案 0 :(得分:0)

而不是

Arr = Range("[wrongemails.csv]wrongemails!$A$1:[wrongemails.csv]wrongemails!$A$4000")

使用:

 ThisWorkbook.Worksheets("Sheet1").Range("[wrongemails.csv]wrongemails!$A$1:[wrongemails.csv]wrongemails!$A$4000")

将Sheet1更改为" Sheet1"

的实际名称