View Full Version : Issue with Space in Path for Output File
ronjon65
01-03-2016, 09:14 AM
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
What is the problem with refraining from the use of spaces in filenames ?
ronjon65
01-03-2016, 02:18 PM
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.
I've never had that problem. Can you provide more details about when it happens.
ronjon65
01-03-2016, 03:41 PM
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.
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 & """"
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.