Consulting

Results 1 to 6 of 6

Thread: Issue with Space in Path for Output File

  1. #1

    Issue with Space in Path for Output File

    If I use the following code, with a path in Cell A1, it works. However, if the path has a space in it, then it will not work. This is for Excel 2003. I suspect there must be a way to allow it to have a path with spaces in it (i.e. "Program Files").

     Open Cells(1, 1) & "\file.txt" For Output As #FileNo

  2. #2
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    What is the problem with refraining from the use of spaces in filenames ?

  3. #3
    Two problems on user end:

    - User may choose a path with a space. Sure you can warn them, but its still going to happen.
    - A path with "Program Files" is preferred in this case.

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    I've never had that problem. Can you provide more details about when it happens.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  5. #5
    After a little more trial and error, it seems the issue was that the "Program Files" directory did not have write permission. I ran into another problem further down the road with the space (a shell procedure) and basically just going to give up on trying to allow for a space in the path.

  6. #6
    VBAX Expert
    Joined
    Oct 2012
    Posts
    726
    Location
    For shell, you probably just need to enclose the path in quotes.


    s = "C:\New folder\test file.txt"
    
    
    'write the file
    ff = FreeFile
    Open s For Output As #ff
    Print #ff, "hello"
    Close #ff
    
    
    'open the file
    Shell "notepad " & """" & s & """"

Posting Permissions

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