I have the following code in an excel macro. All I need to do is put a space between my string and the date string that comes out of the format however, I get only the string part if I remove the string I get only the date obviously.
filenamestring = "CMC_Rates " & Format(Now(), "yyyymmdd")
any ideas?
Here’s more code
Dim filenamestring As String
Dim location As String
Dim passparam As String
location = Year(DateTime.Now) & "/" & Month(DateTime.Now)
filenamestring = "CMC_Rates " & Format(Now(), "yyyymmdd ") & Format(Range("EffTime").Value, "hhmm AMPM") & ".pdf"
passparam = location & "/" & filenamestring
Call Shell(Environ$("COMSPEC") & " /c \\atlanta2-0\MKTG\Rates\SaveFile.bat " & filenamestring, vbNormalFocus)
SaveFile.bat has this in it
pscp -batch -pw password filename.xlsx admin@172.17.1.5:/Path/%1
When it opens the bat it says the paramater is just CMC_Rates, however if I take out the space and put it all together it works.
the problem is with this line: (split for readability)
when Excel calls your batch file, the COMSPEC interpreter treats the filename as more than one argument, as spaces are used as separators. To indicate the filename is one argument, and not many, it needs to be enclosed in quotes “
This will change the line to this: