View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.misc
Bob Phillips Bob Phillips is offline
external usenet poster
 
Posts: 10,593
Default Macro for creating dynamic filenames

Try it and see, you might be surprised.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Brian Beck" wrote in message
...
But wouldn't this just append the month to the filename for each entry in
the spreadsheet?

So if I had the following entry in the excel file:

BusinessName LetterID Month
ACME C06-089 Mar
ACME C06-089 Mar
ACME C06-089 Apr
ACME C06-089 Apr
BusA C06-090 Apr
BusA C06-090 May

Wouldn't I end up with the following filenames?:

ACME_C06-089_Mar
ACME_C06-089_Mar
ACME_C06-089_Apr
ACME_C06-089_Apr
BusA_C06-090_Apr
BusA_C06-090_May

What I'm wanting to get is the following:

ACME_C06-089_MarApr
ACME_C06-089_MarApr
ACME_C06-089_MarApr
ACME_C06-089_MarApr
BusA_C06-090_AprMay
BusA_C06-090_AprMay

All of the ACME entries are going to end up in 1 letter, so I only need 1
filename to use for that letter....same with BusA and so on.

-Brian
"Bob Phillips" wrote in message
...
Function DynFilename(Business, LetterId) As String
Dim cell As Range
DynFilename = Business & "_" & LetterId & "_"
For Each cell In ActiveSheet.Range("Businesses")
If cell.Value = Business And cell.Offset(0, 1).Value = LetterId
Then
DynFilename = DynFilename & Format(cell.Offset(0, 2).Value,
"mmm")
End If
Next cell

End Function



--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Brian Beck" wrote in message
...
I'm sure this is going to end up being convoluted, but if anyone can

help
with this I will be so ecstatic!

I have an excel file that contains business names (Business), a unique

ID
that will be used later for generating a letter (LetterID), and a month
field that tracks what month a particular order took place (Month).
There
are other fields, but these are the only ones I'm concerned with. I

will
be
using this excel file for a mail merge with a letter template that will
generate a letter for each of the businesses in the list. There will

be
an
entry in the spreadsheet for everytime a business placed an order, so

if
Business XYZ placed 12 orders for the time period I'm dealing with,

then
there will be 12 instances of "XYZ" in the Business column of the
spreadsheet...and the month column will contain either Mar, Apr, or May
depending on when the order was placed.

Here is the problem...I'm wanting to add a field to the spreadsheet
called
"Filename" that will concatenate together the business name, the unique
letter ID used for them this letter, and the months that the letter

will
include information for. So essentially the filename template would

look
like this:

BusinessName_LetterID_Months06

where Months could be any combination of Mar, Apr, and/or May and the

06
is
just marking the year.

Now concatenating the first 2 things is no problem...but figuring out

how
to
determine whether the Months should be Mar, MarApr, MarMay, MarAprMay,

Apr,
AprMay, or May is causing me to pull my hair out. It's easy enough if

there
is only one entry for a business because then obviously the "Months"

part
of
the filename will simply be whatever value is in "Month"...but if there
is
more then one entry for the business, how can I programmatically find

out
which months need to be included in the filename?

I hope this makes sense...my brain seems to be turning to mush over

this.

-Brian