获得“未定义的用户定义类型".尝试在VBA中使用WinSCP .NET程序集将文件上传到SFTP时 [英] Getting "user defined type not defined" when trying to use WinSCP .NET assembly in VBA to upload file to SFTP
本文介绍了获得“未定义的用户定义类型".尝试在VBA中使用WinSCP .NET程序集将文件上传到SFTP时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试开发代码以将文件保存在SFTP服务器中,但是在Session
中出错,并显示错误为
I am trying to develop code for save the file in SFTP server but error in Session
and showing error as
未定义用户定义的类型
user defined type not defined
我不确定下面的代码是否正常工作,我是从互联网来源复制代码的.
I am not sure below code working or not and I copied the code from internet source.
任何建议将不胜感激.
Sub test()
Dim wb As Workbook
Set wb = "D:\Ashok\Work\Loan_Input_Template V8-Library.xlsx"
Dim mySession As New Session
' Enable custom error handling
On Error Resume Next
Call Upload(mySession, wb)
' Query for errors
If Err.Number <> 0 Then
MsgBox "Error: " & Err.Description
' Clear the error
Err.Clear
End If
' Disconnect, clean up
mySession.Dispose
' Restore default error handling
On Error GoTo 0
wb.Close SaveChanges:=True
'FileSystemObject.DeleteFile sPathName
End Sub
Private Sub Upload(ByRef mySession As Session, ByRef wb1 As Workbook) 'error line
Dim wb As Workbook
Set wb = Workbooks(wb1)
' Setup session options
Dim mySessionOptions As New SessionOptions
With mySessionOptions
.Protocol = Protocol_SFTP
.HostName = "103.231.8.66"
.UserName = "username"
.Password = "password"
.SshHostKeyFingerprint = "ssh-ed25519 256 df:94:44:56:1b:c2:75:8b:b4:58:3a:e2:ef:2e:0d:78"
End With
' Connect
mySession.Open mySessionOptions
' Upload files
Dim myTransferOptions As New TransferOptions
myTransferOptions.TransferMode = TransferMode_Binary
Dim transferResult As TransferOperationResult
Set transferResult = mySession.PutFiles(wb1, "/home/sftpcf/", False, myTransferOptions)
' Throw on any error
transferResult.Check
' Display results
Dim transfer As TransferEventArgs
For Each transfer In transferResult.Transfers
MsgBox "Upload of " & transfer.FileName & " succeeded"
Next
End Sub
推荐答案
确保已遵循以下说明:
- Installing the WinSCP .NET assembly and
- Registering it for COM and
- Using it from VBA.
这篇关于获得“未定义的用户定义类型".尝试在VBA中使用WinSCP .NET程序集将文件上传到SFTP时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文