View Single Post
  #12   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones Norman Jones is offline
external usenet poster
 
Posts: 5,302
Default Reference a cell as the file name

Hi Cory,

Firstly. apologies for the unintententional attempt to change your gender!

If I understand your intentions, and assuming that the address of the cell
of interest is constant on each sheet, try replacing the sheet reference
with the ActiveSheet property:

'=============
Public Sub Tester001()
Dim rng As Range

Set rng = ActiveSheet.Range("B20")

ActiveWorkbook.SaveAs _
Filename:=rng.Value & ".xls", _
FileFormat:=xlWorkbookNormal

End Sub
'<<=============

---
Regards,
Norman



"promiscuousman" wrote in message
...
This is the macro I eneded up creating
Public Sub Tester001()
Dim rng As Range

Set rng = Sheets("Sheet1").Range("B20") '<<==== CHANGE

ActiveWorkbook.Saveas _
Filename:=rng.Value & ".xls", _
FileFormat:=xlWorkbookNormal

End Sub
B20 is the cell I wish to save as, in sheet one, but if they use sheet two
instead it's a different cell (they will never use both sheets in the
workbook at the same time) is there a way to make it recognize the active
sheet, and base the cell number off of the sheet name?
Admittedly I don't know much about this code stuff, I took an intro class
to
it, and I've got an idea how it works, declaring variables and such, and I
can kind of follow a code somebody else wrote, and see what it's doing,
but I
won't be able to write my own, yet.
Thanks for the help,
Cory
"Norman Jones" wrote:

Hi PromiscuousWoman,

Try something like:

'=============
Public Sub Tester001()
Dim rng As Range

Set rng = Sheets("Sheet1").Range("A1") '<<==== CHANGE

ActiveWorkbook.Savas _
Filename:=rng.Value & ".xls", _
FileFormat:=xlWorkbookNormal

End Sub
'<<=============


Change the sheet name and the range to accord with your needs.

---
Regards,
Norman



"promiscuousman" wrote in
message
...
I want to do something very similar to this. I made a template for my
dad
with 3 different sheets. He will be using only one of these sheets
each
time
the template is opened, and saving it as a number entered in one of the
cells. How would I create a macro that will put the cell value as the
file
name?

Thanks,
Cory