Excel - A macro to edit file name

December 2016




Issue


I have a macro code to save a file name to a form. My file takes two cells (F4) and (H20) to create a backup file. I wan put a hyphen between the two cells nd tried this:

File_Name = Worksheets("Sheet1").Range("F4") & Worksheets("Sheet1").Range("H20") & ".xlsm"


The result generated takes this form F4H20 and I wish it was F4-H20.

Solution


Try this:

File_Name = Worksheets("Sheet1").Range("F4") & "-" & Worksheets("Sheet1").Range("H20") & ".xlsm" 


Thanks to f894009 for this tip.

Related :

This document entitled « Excel - A macro to edit file name » from CCM (ccm.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.