Yes, you can do this with VBA. I will be making a few assumptions here, and
will outline the assumptions in this proposed solution.
1) Press Alt + F11, to open the Visual Basic Editor (VBE)
2) Press Ctrl + R, to open the Project Explorer (PE; if not already open)
3) Select your file in left (PE)
4) Select Insert (menu) | Module
5) Copy/Paste the below code in the right (blank) pane
6) Press Alt + Q, to return to Excel
7) From the Forms toolbar, select a Command Button, create one on your sheet
where desired
8) A dialog box will come up (Assign Macro), select 'SaveTheWorkbookPlease'
and click Ok.
9) Ensure Macro security is Medium or lower (Tools | Macros | Security)
10) Save your workbook before anything else, so no work is lost.
Code to copy:
Option Explicit
Sub SaveTheWorkbookPlease()
Dim rngPO as range
Dim strName as string, strPath as string
Set rngPO = Sheets("Sheet1").Range("A1") '*
strName = ThisWorkbook.Name
strPath = Left(ThisWorkbook.Fullname, Len(ThisWorkbook.Fullname) -
Len(strName))
If Len(rngPO.Text) = 0 Then Exit Sub
ThisWorkbook.SaveAs strPath & rngPO.Text & ".xls" '**
End Sub
'* This assumes certain that your PO will be in Sheet1 in cell A1. Change
as needed.
'** Assumes you want it in the same path as the file you are saving from.
Please Note: There is no error handling in this for invalid characters so
the routine will error out. If that is not necessary you should be good to
go. It it's a possibility, I would either use Data | Validation to restrict
them from being entered in the cell. We can always test afterwards (in the
procedure) but I believe Preventative Maintenance (PM) is always best.
HTH