+ Reply to Thread
Results 1 to 2 of 2

GetSaveasFileName

  1. #1
    Libby
    Guest

    GetSaveasFileName

    Hi

    I have a read-only file and I want to display the SaveAs dialog box and
    suggest a filename which is a date on the worksheet, when either Save or
    SaveAs is clicked.

    I had a problem with the SaveAs dialog box being displayed twice as it was
    readonly file but I think I've cured that. The problem now is that the
    Workbook is saved with the suggested filename even if the user trys to change
    it to something else.

    Here is my code

    Public SAflag as boolean 'true if BeforeSave run

    Private Sub Workbook_Open
    SAflag = False
    end sub

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel as Boolean)
    dim fName
    if IsDate(Sheet1.range("b3").value)=true then
    fName = format(Datevalue(Sheet1.range("b3").value), "dd-mm-yyyy")
    end if
    if SAflag = false then
    if SaveAsUI = true then
    Cancel = True
    Application.GetSaveAsFilename(fName)
    if fName<>False then
    SAflag = True
    Thisworkbook.SaveAs(fName)
    end if
    end if
    end if
    end if
    end sub



    Thanks Guys


  2. #2
    Dave Peterson
    Guest

    Re: GetSaveasFileName

    Maybe just stopping the .saveas from calling the _beforesave would work:

    If fName <> False Then
    SAflag = True
    Application.EnableEvents = False
    ThisWorkbook.SaveAs fName
    Application.EnableEvents = True
    End If

    If it doesn't you may want to paste directly from your code--I think you had a
    typo in your post.

    Libby wrote:
    >
    > Hi
    >
    > I have a read-only file and I want to display the SaveAs dialog box and
    > suggest a filename which is a date on the worksheet, when either Save or
    > SaveAs is clicked.
    >
    > I had a problem with the SaveAs dialog box being displayed twice as it was
    > readonly file but I think I've cured that. The problem now is that the
    > Workbook is saved with the suggested filename even if the user trys to change
    > it to something else.
    >
    > Here is my code
    >
    > Public SAflag as boolean 'true if BeforeSave run
    >
    > Private Sub Workbook_Open
    > SAflag = False
    > end sub
    >
    > Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel as Boolean)
    > dim fName
    > if IsDate(Sheet1.range("b3").value)=true then
    > fName = format(Datevalue(Sheet1.range("b3").value), "dd-mm-yyyy")
    > end if
    > if SAflag = false then
    > if SaveAsUI = true then
    > Cancel = True
    > Application.GetSaveAsFilename(fName)
    > if fName<>False then
    > SAflag = True
    > Thisworkbook.SaveAs(fName)
    > end if
    > end if
    > end if
    > end if
    > end sub
    >
    > Thanks Guys


    --

    Dave Peterson

+ 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