Create a txt file and name it thru macro

[Closed]
Report
-
Posts
4476
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
August 2, 2020
-
Hello,
I am trying to copy content of a worksheet to a text file. What i want to know is how can i name the text file based on a given string in a particular cell. And the issue is that i do not need the complete cell content I want to drop/trim last 4 characters of the cell.
Eg: value in my cell A1 is "abhimanyu_wk2" and i want to create a text file with name only
abhimanyu.
I need script to copy content to text file from a worksheet and name the text file based on the cell A1(as in the example given above).

Any help would be highly appreciated.

Thanks,
Abhimanyu

1 reply

Posts
4476
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
August 2, 2020
768
lastFourChar = Right(Range("A1"), 4)

gives you last 4 characters of cell A1

ActiveWorkbook.SaveAs lastFourChar