Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
LowIQ
 
Posts: n/a
Default 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.
  #2   Report Post  
Posted to microsoft.public.excel.misc
Norman Jones
 
Posts: n/a
Default 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.



  #3   Report Post  
Posted to microsoft.public.excel.misc
SiC
 
Posts: n/a
Default 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.

  #4   Report Post  
Posted to microsoft.public.excel.misc
DCSwearingen
 
Posts: n/a
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compiling macro based on cell values simonsmith Excel Discussion (Misc queries) 1 May 16th 06 08:31 PM
macro save a file name from a cell in 1st worksheet karene Excel Discussion (Misc queries) 2 April 10th 06 12:13 PM
Using "Save As" with a file name selected by cell B Baggins Excel Discussion (Misc queries) 1 September 24th 05 02:07 PM
Macro to remove contents of cell and move all other contents up one row adw223 Excel Discussion (Misc queries) 1 July 1st 05 03:57 PM
This one is tricky....Macro to save file as cell value x in di Andy Excel Discussion (Misc queries) 4 November 26th 04 08:52 AM


All times are GMT +1. The time now is 08:02 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"