Results 1 to 3 of 3

BeforeSave and SaveAs to either save at predefined folder or let the user choose

Threaded View

  1. #1
    Registered User
    Join Date
    12-15-2010
    Location
    SimCity
    MS-Off Ver
    Excel XP
    Posts
    2

    BeforeSave and SaveAs to either save at predefined folder or let the user choose

    Hi all,

    I'm trying to create a macro in order to aks the user whenever he wants to save the workbook whether he wants to either save the active workbook at a predefined folder (predefined by macro) or to name the location as usual when pressing saveas.

    I had some trouble with the beforesave-procedure creating an infinitive loop, but that was solved by using the search function of this forum. My code now looks like this:

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    On Error GoTo ErrorHandler
    Application.EnableEvents = False
    Cancel = True
    Adress = "C:\TEM\test" & Range("b2").Value & ".xls"
    Answer = MsgBox("Save at predefined location?", vbYesNoCancel, "Save")
    If Answer = vbYes Then
    ThisWorkbook.SaveAs Filename:=Adress
    MsgBox "File saved in " & Adress
    ElseIf Answer = vbCancel Then
    MsgBox "File not saved!"
    End If

    ErrorExit:
    Application.EnableEvents = True
    Exit Sub

    ErrorHandler:
    MsgBox "File not saved!"
    Resume ErrorExit

    End Sub


    The only problem I have now is that I can't get the usual saveas dialog running.
    The idea is to save at a predefined location when vbyes is chosen, to abort saving when vbcancel is picked and to get the saveas dialog when vbno is taken.
    I assume that if I set <Cancel = false> in an <elseif answer=vbno> it will just save the workbook at the current location, without the user beeing able to chose where).

    Additionally, maybe someone can explain why I need the ErrorHandler. I tried to trigger it, but whatever button I press, the msgbox never showed (I know because I added the other "file not saved" msgbox later)...

    Thx for any help in advance...

    Greetz - Snyder

    In case this post exists twice now, please remove one... had some network issues and am sorry for that case...
    Last edited by Snyder; 12-16-2010 at 07:38 PM.

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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