子或功能错误 [英] Sub or function error
本文介绍了子或功能错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是vba的新手,我想将数据从一个文件夹中的多张纸传输到一张纸.我编写了如下程序:
I am new to vba, I want to transfer data from multiple sheets in one folder to one sheet. I wrote the programme as follows:
Sub LoopThroughDirectory()
Dim MyFile As String
Dim erow
MyFile = Dir("C:\Bulletinwork\")
Do While Len(MyFile) > 0
If MyFile = "Bmaster.xlsm" Then
Exit Sub
End If
Workbooks.Open (MyFile)
Range("A4:I42").Copy
ActiveWorkbook.Close
erow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
ActiveSheet.Paste Destination:=Worksheets("Sheet1").Range(Cells(erow, 1), Cells(erow, 9))
MyFile = Dir
Loop
End Sub
有人可以帮我找到尝试运行该程序的原因,但是我收到一条错误消息,提示未定义子或函数".
Can someone help me find the reason why when I try to run the programme, I get an error message saying "sub or function not defined".
肯尼
推荐答案
以下行会引起一些悲伤:
The following line will be causing some grief:
Workbooks.Open (MyFile)
()
意味着VBA在运行 Open
命令之前尝试评估 MyFile
.当然, MyFile
是一个字符串/路径,因此无法运行.
The ()
means that VBA is trying to evaluate MyFile
before running the Open
command. Of course, MyFile
is a string/path so can't run.
尝试
Workbooks.Open MyFile
相反.
这篇关于子或功能错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文