Fail in VBScript, VBA (untyped), work in VBA (typed), VB.NET
Some methods of the COM objects fail in VBScript and VBA (with untyped variables), but work in VBA (with typed variables) and VB.NET.
What's wrong? I need to make it work in VBScript.
The VB.NET code works perfectly:
This VBA code also works perfectly:
This VBA code fails:
It says:
at the following statement:
This VBA code also fails (when removing BOTH the declarations, the error message is the same):
It says:
at the following statement:
VBScript code ALWAYS fails:
It says:
:twisted: :twisted: :twisted:
What's wrong? I need to make it work in VBScript.
The VB.NET code works perfectly:
Imports System Imports WinSCP Module Module1 Sub Main() Dim sessionOptions As SessionOptions Dim session As Session sessionOptions = CreateObject("WinSCP.SessionOptions") sessionOptions.Protocol = Protocol.Ftp sessionOptions.FtpSecure = FtpSecure.Implicit sessionOptions.HostName = "***" sessionOptions.UserName = "***" sessionOptions.Password = "***" session = CreateObject("WinSCP.Session") session.Open(sessionOptions) session.SynchronizeDirectories(SynchronizationMode.Local, "***", "***", False) End Sub End Module
This VBA code also works perfectly:
Option Explicit Sub Main() Dim sessionOptions As sessionOptions Dim session As session Set sessionOptions = CreateObject("WinSCP.sessionOptions") sessionOptions.Protocol = Protocol_Ftp sessionOptions.FtpSecure = FtpSecure_Implicit sessionOptions.HostName = "***" sessionOptions.UserName = "***" sessionOptions.Password = "***" Set session = CreateObject("WinSCP.Session") session.Open sessionOptions session.SynchronizeDirectories SynchronizationMode_Local, "***", "***", False End Sub
This VBA code fails:
Option Explicit Sub Main() Dim sessionOptions ' <-- !!! Removed type declaration Dim session As session Set sessionOptions = CreateObject("WinSCP.sessionOptions") sessionOptions.Protocol = Protocol_Ftp sessionOptions.FtpSecure = FtpSecure_Implicit sessionOptions.HostName = "***" sessionOptions.UserName = "***" sessionOptions.Password = "***" Set session = CreateObject("WinSCP.Session") session.Open sessionOptions session.SynchronizeDirectories SynchronizationMode_Local, "***", "***", False End Sub
Invalid procedure call or argument
session.Open sessionOptions
This VBA code also fails (when removing BOTH the declarations, the error message is the same):
Option Explicit Sub Main() Dim sessionOptions As sessionOptions Dim session ' <-- !!! Removed type declaration Set sessionOptions = CreateObject("WinSCP.sessionOptions") sessionOptions.Protocol = Protocol_Ftp sessionOptions.FtpSecure = FtpSecure_Implicit sessionOptions.HostName = "***" sessionOptions.UserName = "***" sessionOptions.Password = "***" Set session = CreateObject("WinSCP.Session") session.Open sessionOptions session.SynchronizeDirectories SynchronizationMode_Local, "***", "***", False End Sub
Object doesn't support this property or method
session.SynchronizeDirectories SynchronizationMode_Local, "***", "***", False
VBScript code ALWAYS fails:
<job> <reference object="WinSCP.Session" /> <script language="VBScript"> Option Explicit Dim sessionOptions Dim session Set sessionOptions = CreateObject("WinSCP.SessionOptions") sessionOptions.Protocol = Protocol_Ftp sessionOptions.FtpSecure = FtpSecure_Implicit sessionOptions.HostName = "***" sessionOptions.UserName = "***" sessionOptions.Password = "***" Set session = CreateObject("WinSCP.Session") session.Open sessionOptions session.SynchronizeDirectories SynchronizationMode_Local, "***", "***", False </script> </job>
Module1.wsf(19, 10) Microsoft VBScript runtime error: Object doesn't support this property or method: 'SynchronizeDirectories'