2012-09-26 34 views
1

我有以下代码VBA编辑器转换文件夹到文件夹,当我使用变量

Dim fileSystemObject As New fileSystemObject 
Dim sourceFolder As folder 
Set sourceFolder = fileSystemObject.GetFolder(sourceFolderPath) 
processFolder (sourceFolder) 

而且processFolder过程声明为

Sub processFolder(folderToProcess As folder) 
'Code here 
End Sub 

我感到奇怪的是抛出一个数据类型不匹配每当我用大写'F'键入Folder时,VBA编辑器会将它转换为一个小'f'的文件夹。我收到一个编译错误消息,当我调用该过程时,存在类型不匹配。有人能告诉我我在这里做错了吗?

回答

2

括号在这里;

processFolder (sourceFolder) 

转换sourceFolder到不能传递的东西串期待Folder这样反而;

processFolder sourceFolder 
+0

感谢您的快速响应。我已经在声明中初始化了filesystemobject。我将更新问题中的代码以显示声明。 –

+0

啊,更新超过 –

+1

或者你可以使用'调用processFolder(sourceFolder)',如果你觉得它看起来更好,因为它是相同的。 –