传递类模块的实例

时间:2015-01-08 15:37:04

标签: vba excel-vba excel

假设我创建了一个类模块的新实例。在该实例块中,我调用另一个调用类模块中的函数的子。我怎么能做到这一点?目前我无法弄清楚它是如何完成的。以下是我的代码概述:

...
With New FTPClient

    .ServerName = strServer
    .UserName = strUserName
    .Password = strPassword
    .remoteDir = strRemoteFolder
    .TransferType = "BINARY"
    .OpenFTP
    .OpenServer

    Upload()

    .CloseServer
    .CloseFTP

End With
...

Function Upload()

   ...
   .PutFile .remoteDir, currentFile, currentPath, "BINARY"
   ...

End Function

.PutFileFTPClient中的方法。)。显然它有点合适,并且不知道.PutFile.remoteDir是什么。有没有办法将FTPClient的实例传递给Upload

谢谢,

1 个答案:

答案 0 :(得分:2)

如果它的作用域在调用代码中,则需要传递它:

set client = new FTPClient
with client
   .ServerName = strServer
   ...
   Upload(client)


Function Upload(client as FTPClient)
   with client
      .PutFile .remoteDir, currentFile, currentPath, "BINARY"