Differences

This shows you the differences between the selected revisions of the page.

library_vb 2017-01-12 library_vb 2022-10-21 (current)
Line 1: Line 1:
====== Using WinSCP .NET Assembly from Visual Basic for Applications (VBA) ====== ====== Using WinSCP .NET Assembly from Visual Basic for Applications (VBA) ======
-===== Installing and Registering for COM =====+===== [[installing]] Installing and Registering for COM =====
First, you need to [[library_install|install the WinSCP .NET assembly and register it for COM]]. First, you need to [[library_install|install the WinSCP .NET assembly and register it for COM]].
-Note that Microsoft Office applications are 32-bit, so you need to register the assembly for 32-bit .NET framework, even on 64-bit systems.+Check if your installation of Microsoft Office is 32-bit or 64-bit and [[library_install#registering|register]] the assembly accordingly.
===== [[using]] Using from VBA ===== ===== [[using]] Using from VBA =====
Line 22: Line 22:
  * Implement your interactions with WinSCP .NET assembly in a class module;   * Implement your interactions with WinSCP .NET assembly in a class module;
  * Declare private variable in your class module referring to ''[[library_session|Session]]'' class;   * Declare private variable in your class module referring to ''[[library_session|Session]]'' class;
-  * Use ''[[msdn>gg251653|WithEvents]]'' keyword, when declaring the private variable;+  * Use [[https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/private-statement|''WithEvents'' keyword, when declaring the private variable]];
  * Define private function (method) with name ''<variablename>_<event>'' and two arguments (e.g. ''sender'' and ''e'') for every event you need to handle.   * Define private function (method) with name ''<variablename>_<event>'' and two arguments (e.g. ''sender'' and ''e'') for every event you need to handle.
Line 46: Line 46:
VBA does not support catching exceptions, what is a common way of handling errors in examples for most other languages. VBA does not support catching exceptions, what is a common way of handling errors in examples for most other languages.
-In case you need to use custom error handling, instead of interrupting a VB macro (the default behavior), use ''[[msdn&gt;gg251688|On Error]]'' statement.+In case you need to use custom error handling, instead of interrupting a VB macro (the default behavior), use ''[[https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/on-error-statement|On Error]]'' statement.
-Use ''On Error Resume Next'' to disable default error handling. Then you need to query ''[[msdn&gt;gg251525|Err.Number]]'' after every statement to test for errors. You can revert to default error handling (aborting the macro) using ''On Error GoTo 0''.+Use ''On Error Resume Next'' to disable default error handling. Then you need to query ''[[https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/err-object|Err.Number]]'' after every statement to test for errors. You can revert to default error handling (aborting the macro) using ''On Error GoTo 0''.
<code vb> <code vb>
Line 161: Line 161:
        .UserName = "user"         .UserName = "user"
        .Password = "mypassword"         .Password = "mypassword"
-        .SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"+        .SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxx..."
    End With     End With
       
Line 172: Line 172:
       
    Dim transferResult As TransferOperationResult     Dim transferResult As TransferOperationResult
-    Set transferResult = mySession.PutFiles("d:\toupload\*", "/home/user/", False, myTransferOptions)+    Set transferResult =
 +········mySession.PutFiles("d:\toupload\*", "/home/user/", False, myTransferOptions)
       
    ' Throw on any error     ' Throw on any error

Last modified: by martin