+ Reply to Thread
Results 1 to 3 of 3

Restoring Save functions after Workbook_BeforeSave

Hybrid View

  1. #1
    Registered User
    Join Date
    10-25-2007
    Location
    Melbourne, Australia
    Posts
    27

    Cannot save from Task bar after saving from macro

    I have created a workbook that is used by a team as a template. It should be opened and then saved with a new name to a new location. To protect the “master” file the routine provides a filename constructed from key cells in the workbook when saving for the first time. The file saving works fine but when I next try the ‘Save’ or ‘Save As’ functions from the Menu or Task bars, they are disabled.
    I tried adding in the ‘EndOfSub:’ block the line “Cancel=False”, thinking this would turn on the ‘Save’ dialog, but Excel hangs, then shuts down.
    Can anyone please offer any insight to my problem?
    Thanks in advance.

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
       
    Dim NewFileName As String
    Dim Instr1 As String
    Dim Response As Integer
    '   Error Trap
    On Error GoTo Etrap
    Instr1 = "Save Manufacturing Study file as:"
    NewFileName = Worksheets("Data").Range("NewFileName")
    Application.EnableEvents = False
    Cancel = True
    '   Check if new or existing file
    MyName
    If MyName <> "Manufacturing Study_v3.0.xls" Then
        GoTo EndOfSub
    End If
    '   Check parts of FileName
    If Worksheets("Summary").Range("PROC") = "" Or Worksheets("Summary").Range("LOCN") = "" Then
        MsgBox "Please type in Process description and Location, for automatic file name", vbInformation, "Manufacturing Study Save"
        GoTo EndOfSub
    End If
    '   Ask User to Save
    Response = MsgBox(NewFileName, vbYesNoCancel, Instr1)
    Select Case Response
    Case vbYes '   Save active workbook as new workbook
            ThisWorkbook.SaveAs Filename:=NewFileName, FileFormat:=xlNormal, _
               Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
               CreateBackup:=False, AddToMru:=True
            MsgBox "New Workbook File Saved", vbInformation, "Manufacturing Study Save"
            GoTo EndOfSub
    Case vbNo
        MsgBox "Be sure to 'SAVE AS' in correct folder." & Chr(13) & "Workbook changes not saved!", vbInformation, "Manufacturing Study Save"
        GoTo EndOfSub
    Case vbCancel
        GoTo EndOfSub
    End Select
    Etrap:
        Beep
        MsgBox "Workbook changes not saved!", vbExclamation, "Manufacturing Study Save"
    EndOfSub:
        Application.EnableEvents = True
        '    Cancel = False
        Exit Sub
    End Sub
    Last edited by jagman; 10-29-2007 at 04:44 PM. Reason: No answers received

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887
    Hi jagman,

    Welcome to the forum. In the future please wrap all VBA code in your posts by clicking on the # symbol in the text editor.

    I've done it for you this time, but future posts may be deleted. Please review the forum rules for posting. (Link in my signature)

    Thanks!

  3. #3
    Registered User
    Join Date
    10-25-2007
    Location
    Melbourne, Australia
    Posts
    27

    Excel crashes with "Save As" from macro

    Thanks Paul, for your helpful treatment of a newcomer. I now understand what it is to "wrap" code.
    I assigned the macro code to a button in order to bypass the BeforeSave event and Excel still crashed. Therefore, there must be another issue I have no clue about.
    My "NewFileName" is a concatenated text string built from nine cells and can easily be over 150 characters long.
    Can anyone tell me if there are restrictions on how file names are put together and used that may be causing my problems? Some saves have been successful with the same text string, though.
    Thanks for your time and assistance.

+ 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