Excel VBA - Save file if it has not been saved yet

Posted on 2011-10-31
Last Modified: 2012-05-12
I am sending an Excel file as an email attachment and want code to check if the file has been saved.  If it has NOT been saved, then prompt the user to save with the same name as the file already has.

It can be saved anywhere.

Thanks, --Andres
Question by:AndresHernando
    LVL 85

    Accepted Solution

    For example:

       Dim SaveName          As Variant
       If ActiveWorkbook.Saved = False Then
          SaveName = Application.GetSaveAsFilename( _
          If SaveName <> False Then ActiveWorkbook.SaveAs SaveName
       End If

    Open in new window


    Author Closing Comment

    Thanks Rory.  Just what I needed.   --Andres

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
    Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
    The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
    This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now