![]() |
How to save file in a macro taking new name from cell contents?
I want to Save-as a file from within a macro, taking the new name from the
worksheet's cell contents. I want to save an order form with a file name based on the order number contained in a worksheet cell. My question is how to get the cell contents into the Save-as dialog box when the macro calls the Save-as function. Thanks. |
How to save file in a macro taking new name from cell contents?
Hi LowIQ,
Try: '============= Public Sub Tester004() Dim sStr As String sStr = ThisWorkbook.Sheets("Sheet1"). _ Range("A1").Value '<<=== CHANGE ThisWorkbook.SaveAs Filename:=sStr & ".xls", _ FileFormat:=xlWorkbookNormal End Sub '<<============= --- Regards, Norman "LowIQ" wrote in message ... I want to Save-as a file from within a macro, taking the new name from the worksheet's cell contents. I want to save an order form with a file name based on the order number contained in a worksheet cell. My question is how to get the cell contents into the Save-as dialog box when the macro calls the Save-as function. Thanks. |
How to save file in a macro taking new name from cell contents?
Assuming your order number is in cell A1,
ActiveWorkbook.SaveAs Filename:=cells(1, 1).value & ".xls" -Simon "LowIQ" wrote: I want to Save-as a file from within a macro, taking the new name from the worksheet's cell contents. I want to save an order form with a file name based on the order number contained in a worksheet cell. My question is how to get the cell contents into the Save-as dialog box when the macro calls the Save-as function. Thanks. |
How to save file in a macro taking new name from cell contents?
I have used the following technique quite a bit. the ActiveWorkbook.FullName returns the active workbook name and path; e.g. C:\My Documents\MyName\MyBook.xls Private Sub SaveInvoiceNo () dim myInvoiceName as string, myNumber as String myNumber = Worksheets("Invoice").Range("E1").Value myInvoinceName = ActiveWorkbook.FullName myInvoiceName = Left(myInvoiceName, Len(MyInvoiceName) - 4) myInvoiceName = myInvoiceName & "_" & mynumber & ".xls" ActiveWorkbook.SaveCopyAs Filename:=myInvoiceName end sub -- DCSwearingen Getting old, but love computers. ------------------------------------------------------------------------ DCSwearingen's Profile: http://www.excelforum.com/member.php...o&userid=21506 View this thread: http://www.excelforum.com/showthread...hreadid=547247 |
All times are GMT +1. The time now is 02:43 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com