• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 537
  • Last Modified:

vb macro strFileName based in field in excel sheet


how can i make my output file name exported from excel (using a macro) be named after a field in the excel sheet itself?

i.e. the value from B1 from sheet 1

strDefFolder = Trim(InputBox(" Enter path to save file", "File Location", ""))
system = field B1

strFileName = system & Day

All help will do
1 Solution
QlemoBatchelor and DeveloperCommented:
You can use e.g. System = [B1].Value or System = Range("B1").Value if you are in Sheet1, or System = [Sheet1!B1].Value if in another sheet. Even better, name your field, and use that name instead of B1.
suppose field B1 contains "myfile.txt" and field B1 resides in worksheet sheet1, the solution could be something in the line of:

dim temp as variant
temp = Split(worksheets("sheet1").range("B1").value,".")
strFileName = temp(0) & Date & "." & temp(1)

resulting in strFilename containing "myfile26-12-2013.txt"
(atleast it would be in Dutch date notation :-) )
rutgermonsAuthor Commented:
Thanks CvD, your comment was the most complete solution and worked for me!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now