Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Jun 2001
    Location
    Virginia, USA
    Posts
    127
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Wscript FTP applicaiton (VBA )

    (Edited by HansV to make URL clickable - see <!help=19>Help 19<!/help>)

    My Access XP application needs to send and receive files from an FTP server each day. I found this code
    on a website (thanks to http://www.sqlservercentral.com/columnists...tomatetasks.asp) and
    attempted to modify it to meet my needs. However the error message:
    "Compile Error: Variable Not Defined" appears when I attempt to run it. The variable in question is Wscript on
    the line

    Set objShell = Wscript.CreateObject("WScript.Shell")
    I tried to set a reference to Microsoft WMI Scripting but it did not help.

    Any ideas what is going on here?

    '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''
    Sub GetMyFiles()
    Dim objFSO, objMyFile, objShell, strFTPScriptFileName, strFile2Get
    Dim strLocalFolderName, strFTPServerName, strLoginID
    Dim strPassword, strFTPServerFolder


    'Customize code here to fit your needs
    strLocalFolderName = "C:temp"
    strFTPServerName = "FTP://somesite.net/"
    strLoginID = "abcftp"
    strPassword = "abc"
    strFTPServerFolder = "some_FTP_Folder"


    strFile2Get = "TestDownload.txt"

    'The following code generates the file name on the FTP server you want to get
    'strFile2Get = "Data" & strFile2Get & ".csv"

    'The follow lines of code generate the FTP script file on the fly,
    'because the get file name changes every day

    strFTPScriptFileName = strLocalFolderName & "FTPScript.txt"

    Set objFSO = CreateObject("Scripting.FileSystemObject")

    If (objFSO.FileExists(strFTPScriptFileName)) Then
    objFSO.DeleteFile (strFTPScriptFileName)
    End If

    Set objMyFile = objFSO.CreateTextFile(strFTPScriptFileName, True)
    objMyFile.WriteLine ("open " & strFTPServerName)
    objMyFile.WriteLine (strLoginID)
    objMyFile.WriteLine (strPassword)
    objMyFile.WriteLine ("cd " & strFTPServerFolder)
    objMyFile.WriteLine ("ascii")
    objMyFile.WriteLine ("lcd " & strLocalFolderName)
    objMyFile.WriteLine ("get " & strFile2Get)
    objMyFile.WriteLine ("bye")
    objMyFile.Close
    Set objFSO = Nothing
    Set objMyFile = Nothing

    'The following code executes the FTP script. It creates a Shell
    'object and run FTP program on top of it.

    Set objShell = Wscript.CreateObject("WScript.Shell") 'THIS IS THE LINE THAT ALWAYS BOMBS!!!'

    objShell.Run ("ftp -s:" & Chr(34) & strFTPScriptFileName & Chr(34))
    Set objShell = Nothing

    Thanks,

  2. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 15 Times in 15 Posts

    Re: Wscript FTP applicaiton (VBA )

    Try changing the line to

    Set objShell = CreateObject("WScript.Shell")

  4. #3
    2 Star Lounger
    Join Date
    Jun 2001
    Location
    Virginia, USA
    Posts
    127
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wscript FTP applicaiton (VBA )

    Thanks Hans. Can you tell me why this change worked where the original line of code did not?

  5. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 15 Times in 15 Posts

    Re: Wscript FTP applicaiton (VBA )

    CreateObject is a general VBA function, it can be used without prefixing it with anything. You can't use WScript to create a WScript object.

  6. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Wscript FTP applicaiton (VBA )

    Your code example is from a different context: a VBScript file executing against the Windows Script Host. Just as the VBA/Office environment is aware of certain top level objects by default and not others, so with VBScript.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •