ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Save Spreadsheet As 2 or 3 cell values (https://www.excelbanter.com/excel-programming/435494-save-spreadsheet-2-3-cell-values.html)

Vic49

Save Spreadsheet As 2 or 3 cell values
 
I would like to automatically name the the file with some static text and
thevalues from 2 or 3 cells. For example:

I am creating a expense account and I would like the the name to be:
XYZ_Expenses_"Date"_"Amount"

Whe
XYZ_Expenses is Static test,
Date is located in cell J3,
Amount is located in cell J30

I am not very familiar with using or building macros, so any information on
how to build and run the macro and would be greatly appreciated. Thanks in
advance.

Win XP and Excel 2007

geoff_ness

Save Spreadsheet As 2 or 3 cell values
 
On Oct 28, 9:56*am, Vic49 wrote:
I would like to automatically name the the file with some static text and
thevalues from 2 or 3 cells. For example:

I am creating a expense account and I would like the the name to be:
XYZ_Expenses_"Date"_"Amount"

Whe
XYZ_Expenses is Static test,
Date is located in cell J3,
Amount is located in cell J30

I am not very familiar with using or building macros, so any information on
how to build and run the macro and would be greatly appreciated. Thanks in
advance.

Win XP and Excel 2007


I'd recommend naming the cells J3 and J30 as Date and Amount
respectively (Formulas-Define Name). Then try something like the
following:

Sub Rename()
Dim wbkToBeSaved as Workbook
Dim sOldName as String
Dim sDate as String
Dim sAmount as String
Dim sNewName as String
Const sPREFIX = "XYZ_Expenses_"

' Get the workbook you want to rename
sOldName = "" ' Whatever the old name is...
Set wbkToBeSaved = Workbooks(sOldName)

' Build new name
sDate = wbkToBeSaved.Names("Date").RefersToRange.Text
sAmount = wbkToBeSaved.Names("Amount").RefersToRange.Text
sNewName = sPREFIX & sDate & "_" & sAmount

wbkToBeSaved.SaveAs sNewName

End Sub

HTH
Geoff


All times are GMT +1. The time now is 01:14 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com