Loading
Ozgrid Excel Help & Best Practices Forums

Excel Video Tutorials / Excel Dashboards Reports



Results 1 to 7 of 7

Thread: FileCopy with spaces in file name

  1. #1
    Join Date
    1st September 2010
    Posts
    7,907

    FileCopy with spaces in file name

    I can't believe this one has me stumped, but...

    Trying to use FileCopy where the destination file has spaces in it, for example:
    "J:\Location\Department\Data Quality\3. Issues Tracking\Supporting Documentation\Emails\000203\abc.abc"

    I've tried all sorts of gubbins with Chr$(34), multiple quote marks and just about every possible permutation thereof but always get an Error 52 (Bad file name or number). This is related to the destination filename with the spaces. I can FileCopy Source, Source & "XXX" (for example) no problem

    I can also copy the file using Windows Explorer, using a DOS box and a Copy command with quotes around the filename, but no way is it going to happen in code.

    I would appreciate someone else's perspective of this before I start barking...

    Excel Video Tutorials / Excel Dashboards Reports


  2. #2
    Join Date
    9th September 2009
    Posts
    1,599

    Re: FileCopy with spaces in file name

    I am unable to reproduce the error:
    VB:
    FileCopy "C:\Documents and Settings\xxxxx xxxxx\My Documents\Excel\Ozgrid\3. Issues Tracking\File Copy Test 146683.xls", _ 
    "C:\Documents and Settings\xxxxx xxxxx\My Documents\Excel\Ozgrid\3. Issues Tracking\File Copy Test 2 146683.xls" 
    
    
    Works just fine for me. (Well it does without me obliterating my real details )

  3. #3
    Join Date
    1st September 2010
    Posts
    7,907

    Re: FileCopy with spaces in file name

    Thanks Rob - at least it's just me for once.

    I do understand the name must be enclosed in "'s if it includes spaces and I check for that - but for one reason or another it just will not copy to that directory using the variable.

    However, It does copy if I replace the variable with a literal - so back to squinting at the multiple """""'s

    Excel Video Tutorials / Excel Dashboards Reports


  4. #4
    Join Date
    24th January 2003
    Location
    Australia
    Posts
    31,716

    Re: FileCopy with spaces in file name

    My guess is that you aren't joining the variables correctly, or they don't contain the right file/path names and are perhaps missing a back-slash \ . In other words the problem is not the spaces.

  5. #5
    Join Date
    9th September 2009
    Posts
    1,599

    Re: FileCopy with spaces in file name

    A good tip from Barb-b here on ozgrid is to create two constants:
    VB:
    Const Q = Chr(34) 
    Const DQ = Chr(34) & Chr(34) 
    
    
    Then use them when appropriate. Tends to avoid going bleary eyed counting the little ticks.

  6. #6
    Join Date
    1st September 2010
    Posts
    7,907

    Re: FileCopy with spaces in file name

    Thanks for the suggestions - and I always use Chr$(34) in preference to "'s, but this just will not work for me today.
    Strategy to resolve: Save, Shut down, go home, enjoy the weekend...

    Excel Video Tutorials / Excel Dashboards Reports


  7. #7
    Join Date
    9th September 2009
    Posts
    1,599

    Re: FileCopy with spaces in file name

    Sounds like a plan Cytop. Have a good one!

Thread Information

Users Browsing this Thread

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

Possible Answers

  1. Output To CSV Text File Produces Extra Spaces
    By parkrrr in forum EXCEL HELP
    Replies: 2
    Last Post: May 21st, 2008, 23:59
  2. Replies: 1
    Last Post: January 15th, 2008, 12:15
  3. Doing FileCopy even if the file is opened?
    By boisonbeauty342 in forum EXCEL HELP
    Replies: 1
    Last Post: June 6th, 2006, 21:23
  4. Filecopy won't filecopy!
    By bvg in forum EXCEL HELP
    Replies: 6
    Last Post: March 3rd, 2005, 05:22

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
  •  
porno