+ Reply to Thread
Results 1 to 7 of 7

VBA code for directory names with spaces

  1. #1
    Forum Contributor
    Join Date
    08-31-2010
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    204

    VBA code for directory names with spaces

    Hi all, could someone please help me with this annoying problem...I download files from ftp and the current Code that works where it downloads everything in the folder where my excel spreadsheet is with the VBA macro: M:\My FTP\New York\

    Please Login or Register  to view this content.
    However, I want the files to be downloaded to:M:\My FTP\New York\Files

    I tried couple things and neither worked:
    Please Login or Register  to view this content.
    Also with double quotations since there
    are spaces in the file name
    Please Login or Register  to view this content.


    Could someone please help. What am I doing wrong?

    Thanks so much
    Last edited by donyc; 02-23-2011 at 06:18 PM. Reason: wrong title

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VBA code for directory names with spaces

    Hello donyc,

    I am not sure what you want to accomplish. The code you provided simply writes a line of data into a text file. This has nothing to do with selecting a directory.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor
    Join Date
    08-31-2010
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    204

    Re: VBA code for directory names with spaces

    right so it writes the batch which gets executed and file gets downloaded from ftp into the specified folder..it seems it will only download into a folder directory which contains no spaces.. as soon as I list the directory name which contains spaces the macro does not download anything

  4. #4
    Forum Contributor
    Join Date
    08-31-2010
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    204

    Re: VBA code for directory names with spaces

    Hi to add here is the full code I use..I am creating a batch file which upon execution downloads the files to specified directory from ftp..
    The code works when I let it download to the path the current workbook is in but not when I specify the full path 1 folder deeper it does not work.. I use the below code in red( the full code is below)

    This is last thing that is keeping me from finishing this project. Any help would be greatly appreciated!

    Print #lInt_FreeFile01, "recv myfile.txt" & """M:\test\New York\Manhattan Streets" & "\myfile.txt"""
    Please Login or Register  to view this content.
    'it works if I use below line, but that just download to the current path(M:\test\New York) where my workbook is saved, I just need the files downloaded 1 folder 'deeper (M:\test\New York\Manhattan Streets)

    Print #lInt_FreeFile01, "recv myfile.txt" & ThisWorkbook.Path & "\myfile.txt;"


    Please Login or Register  to view this content.

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VBA code for directory names with spaces

    Hello donyc,

    This macro may solve your problem. It converts a Windows long path (with spaces and other characters) to a DOS directory format. Copy all the codebelow into the same VBA module.
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    08-31-2010
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    204

    Re: VBA code for directory names with spaces

    thanks Leith..I get Compile Error
    "Only comments may appear after End Sub, End FUnction, or End Property"

    Am I inserting this in the wrong space within my code?

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VBA code for directory names with spaces

    Hello donyc,

    Here are the instructions to copy the macro into a separate module in your VBA project. You will, of course, need to add the macro GetShortPath to your macro.

    Adding the Macro
    1. Copy the macro above pressing the keys CTRL+C
    2. Open your workbook
    3. Press the keys ALT+F11 to open the Visual Basic Editor
    4. Press the keys ALT+I to activate the Insert menu
    5. Press M to insert a Standard Module
    6. Paste the code by pressing the keys CTRL+V
    7. Make any custom changes to the macro if needed at this time.
    8. Save the Macro by pressing the keys CTRL+S
    9. Press the keys ALT+Q to exit the Editor, and return to Excel.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1