Closed Thread
Results 1 to 4 of 4

How to save file in a macro taking new name from cell contents?

  1. #1
    LowIQ
    Guest

    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. #2
    Norman Jones
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    >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. #3
    SiC
    Guest

    RE: 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. #4
    Forum Contributor
    Join Date
    03-24-2005
    Location
    Wisconsin
    MS-Off Ver
    2007
    Posts
    378

    Do you need the Save-as Dialog?

    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
    Thanks!
    Dennis

    I am using Windows 7 and Office 2007, all of my posts are based on this.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1