I need to save a file with some random spaces in the name.
It's in Excel Vba. All I found after one hour of net search are suggestions to either replace the space with %20 or avoid spaces in file name. I tried playing with adding quotes or putting %20 with no luck.
The file produced is for export to a legacy system, changing the names or replacing the space by an another character is not an option.
Also the spaces are not necessarily at the same place and I'd like to avoid putting a Case statement for 20 different names.
Here's the piece of code that causes me trouble.
Savepath=range("a1").value
NameOfFile=range("a2").value
FullnameSave=savepath & "\"& NameOfFile & ".xlsm"
ActiveWorkbook.SaveAs Filename:=FullNameSave, FileFormat:=xlOpenXMLWorkbookMacroEnabled
Everything works fine excepted when there is a space somewhere in FileName.
For example if the value in A2 is StandardPrice the file is saved fine, if it's standard price I get an error (error 1004 on SaveAs method). As well, if I hard code the name as follow, it works.
FullnameSave=savepath & "\" & "standard price" & ".xlsm"
I tried to add 2,3,4 even 5 quotes around the file name but it never returns the correct format (which would be something like H:\Pip_Import\ImportTests2016-10\"standard price"