+ Reply to Thread
Results 1 to 6 of 6

SaveAs macro

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-13-2006
    Location
    League City, TX
    MS-Off Ver
    2010
    Posts
    139

    SaveAs macro

    I have this save as macro that I'm using to save from a certain cell, it works fine but it saves to the last place I saved a previous file how can I have it open up the browse window to choose where I want to save it?
    Here is the macro I'm using

    Public Sub SaveAsA1()
        ThisFile = Range("A1").Value
        ActiveWorkbook.SaveAs Filename:=ThisFile
    End Sub
    Last edited by mrggutz; 08-09-2010 at 11:54 AM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: save as macro

    Open up the VBEditor and put this macro into the ThisWorkBook module, it completely replaces the SAVE function. If it's a SAVEAS, it will offer a name based on the cells desired:
    Option Explicit
    
    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    'Jerry Beaucaire (11/17/2009)  
    'Always offer saveas with cell value from A1 on the a specifically named sheet 
    Dim SvName As String
    
    SvName = Sheets("Sheet1").Range("A1").Value
    Application.EnableEvents = False
    
        If SaveAsUI = True Then
            Application.Dialogs(xlDialogSaveAs).Show SvName
        Else
            Me.Save
        End If
    
    Cancel = True
    Application.EnableEvents = True
    End Sub

    Be sure to edit the sheet name in the macro to the correct one.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Contributor
    Join Date
    05-13-2006
    Location
    League City, TX
    MS-Off Ver
    2010
    Posts
    139

    Re: save as macro

    Thanks for that it works good, but how do i get it to just give me the file name without the extension...example I picked a 1234.jpg in my excel template and when I saved it, it was a .jpg file and not a .xls file. Please advise and thx for the help.
    mrggutz

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: SaveAs macro

    Try this:
    Option Explicit
    
    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    'Jerry Beaucaire (11/17/2009)
    'Always offer saveas with cell value from A1 on the a specifically named sheet
    Dim SvName As String
    
    SvName = Sheets("Sheet1").Range("A1").Value
    If InStr(SvName, ".") > 0 Then SvName = Left(SvName, InStr(SvName, ".") - 1)
    Application.EnableEvents = False
    
        If SaveAsUI = True Then
            Application.Dialogs(xlDialogSaveAs).Show SvName
        Else
            Me.Save
        End If
    
    Cancel = True
    Application.EnableEvents = True
    End Sub


    If that takes care of your need, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  5. #5
    Forum Contributor
    Join Date
    05-13-2006
    Location
    League City, TX
    MS-Off Ver
    2010
    Posts
    139

    Re: SaveAs macro

    I'll give it a try thx.

  6. #6
    Forum Contributor
    Join Date
    05-13-2006
    Location
    League City, TX
    MS-Off Ver
    2010
    Posts
    139

    Smile Re: SaveAs macro

    That worked great thx abunch.

+ 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