+ Reply to Thread
Results 1 to 9 of 9

Generating Save As Name

Hybrid View

  1. #1
    Registered User
    Join Date
    11-19-2009
    Location
    Liverpool, England
    MS-Off Ver
    Excel 2003
    Posts
    11

    Generating Save As Name

    I will be using my Excel worksheet for quoting individual customers and I am wondering whether I can specify that when the save button is pressed that it generates the destination file name from a cell or cells. eg the Customers name and registration. rather than using "save as" option.

    Thanks again

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Generating Save As Name

    This code goes in the Thisworkbook object.

    Uses the contents of A1 and B1 on sheet with a code name of Sheet1.
    You may want to control the path as well as the filename

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    
        Dim strName As String
        
        If SaveAsUI Then
            strName = Sheet1.Range("A1") & "_" & Sheet1.Range("B1").Value
            ThisWorkbook.SaveAs strName
            Cancel = True
            Exit Sub
        End If
        
    End Sub
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    11-19-2009
    Location
    Liverpool, England
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Generating Save As Name

    Brilliant, sorry to sound stupid but where do i enter the code.

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Generating Save As Name

    right click a sheet tab and pick View code.
    In the project window double click the Thisworkbook object

    paste the code in there.

  5. #5
    Registered User
    Join Date
    11-19-2009
    Location
    Liverpool, England
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Generating Save As Name

    Hi,

    I have attached the workbook. I "think" i have followed your instructions correctly however when i press save I don't get the desired result.

    I need the save name to be B3 & B4 eg in this work book Chris Killen LR54UTM.

    Any help would be greatly appreciated.

    Thank you
    Attached Files Attached Files

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Generating Save As Name

    The code is working but it only works when you do a SAVEAS.

    If the workbook has already been saved then the name will not be changed.

    If you use the menu File > Saveas you will see the file is saved with the new details.

+ Reply to 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