Create a txt file and name it thru macro

Closed
abhi - Mar 10, 2012 at 12:49 AM
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 - Mar 24, 2012 at 03:44 PM
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
Related:

1 response

rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Mar 24, 2012 at 03:44 PM
lastFourChar = Right(Range("A1"), 4)

gives you last 4 characters of cell A1

ActiveWorkbook.SaveAs lastFourChar
0