Save as filename cell DETAILS!B2 value

A

alex3867

I've tried searching, perhaps not long enough, for a pre-written macro
code that, when you save the file as, the filename is automatically the
value in a particular cell of a particular sheet.

I have no experience with macros, and changing the codes I HAVE found
to work for me has been of little success :(

The file is a template for invoices, and on one sheet (named DETAILS)
in cell B2 is the invoice number we enter - so when the file is saved I
want the filename to be that number!

How would I write the code, but then also save it and make sure it runs
whenever the file is open?

Any help much appreciated

Thanks
Alex
 
G

Guest

Set up a variable and then use that...

---------

Dim strFileName as String

Sheets("DETAILS").Activate
strFileName = Range("B2").Text

ActiveWorkbook.SaveAs Filename:= {ENTER FILE LOCATION HERE} & strFileName &
".xls"
-----------------

This should work for you. You must note that the File location must be in "
marks and must end with a \ bfore strFileName.

HTH.
 
A

alex3867

Sorry but I'm slight confused:

What is a 'variable'?

And the code:
_________________________
Dim strFileName as String

Sheets("DETAILS").Activate
strFileName = Range("B2").Text

ActiveWorkbook.SaveAs Filename:= {C:\Invoice\strFileName} & strFileName
&
".xls"
_________________________

I could not get to work using VB. I honestly have no idea what I am
doing here :(

Thanks
Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top