Solved

vb macro strFileName based in field in excel sheet

Posted on 2013-12-26
3
476 Views
Last Modified: 2013-12-26
folks

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
0
Comment
Question by:rutgermons
3 Comments
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
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.
0
 
LVL 3

Accepted Solution

by:
CvD earned 500 total points
Comment Utility
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 :-) )
0
 

Author Closing Comment

by:rutgermons
Comment Utility
Thanks CvD, your comment was the most complete solution and worked for me!

cheers
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now