+ Reply to Thread
Results 1 to 26 of 26

Excel shutting down during save

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    4,056

    Excel shutting down during save

    Okay, I've got a strange problem. The macro below WAS (yesterday) working well to save the active workbook to a specific location with a specific name. Now, Excel shuts down when it hits that bit of code. Any idea what would be causing it? BTW, it tries to save to the location; there's an unknown type of fill deposited there, with a name like "7A08C000". If I put an XLS extension on it it says the file format is not valid.

    If I change "ActiveWorkbook" to "TwoB" I get the same result. But, if I make a different workbook the active workbook, the macro works.

    Sub Save()
    Set TwoB = Workbooks("2BDeleted.xls")
            Application.DisplayAlerts = False
            Dim MO As Variant, HO As Variant
            Set MO = TwoB.Sheets("Lookups").Range("H1")
            Set HO = TwoB.Sheets("Lookups").Range("M1")
            Stop
            ActiveWorkbook.SaveAs FileName:= _
                "\\12AUST1001FS01\SHARE10011\Budget\SOBUDGET\CPS\MFR Projections\2011\Current\" & HO & " MFR Projection for " & MO & ".xls", FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
                ReadOnlyRecommended:=False, CreateBackup:=False
    
            Application.DisplayAlerts = True
    End Sub
    EDIT: I edited the post to attach a copy of the Lookups sheet.
    Attached Files Attached Files
    Last edited by jomili; 07-25-2011 at 12:15 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    4,056

    Re: Excel shutting down during save

    Okay, I've done some more testing, and I can narrow down the problem even more.

    The problem seems to be triggered by the HO and MO variants; for some reason Excel doesn't seem happy about those two. Any ideas on another way to do it?

  3. #3
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    4,056

    Re: Excel shutting down during save

    I still need help.

    I tried this morning just saving the active workbook with a new name.
    ActiveWorkbook.SaveAs HO & " MFR Projection for " & MO & ".xls", FileFormat:=xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False
    Same reaction, Excel shuts down and offers to recover my work.

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,978

    Re: Excel shutting down during save

    Two thoughts spring to mind:
    1. Use HO.Value and MO.Value
    2. Don't call your sub Save as that is an Excel method
    Everyone who confuses correlation and causation ends up dead.

  5. #5
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    4,056

    Re: Excel shutting down during save

    Romper,

    Thanks for the advice, but no go. I tried putting .value after MO and HO, and still got the same reaction. "Save" was just a temporary macro, not the full routine, so I changed the name to "SaveIt". As a separate routine, if I just run it over and over, sometimes it will work, sometimes it won't. As part of the larger routine, it fails every time, but catastrophically, by shutting down Excel. I've pasted the larger routine below; it's a lot to go through, but maybe it will give you a clue as to what's happening.
    Sub Finish()
       'Restore the play pivot to its former glory
       Run "Killbutts"
       
       'Now back to the magic
       Set TwoB = Workbooks("2BDeleted.xls")
       'Get the splash page back
       Workbooks("MFR Projection Tool.xls").Sheets("Sheet1").Activate
       
       With Application
            .ScreenUpdating = False
            .EnableEvents = False
            
            TwoB.Sheets("Play").Activate
                    
            'Copy the pivot to our Worksheet page as values and formats
            Set PT = ActiveSheet.PivotTables(1)
            PT.TableRange1.Copy
            TwoB.Sheets("Worksheet").Activate
            
            With TwoB.Sheets("Worksheet").Range("A1")
                .PasteSpecial Paste:=xlPasteValues
                .PasteSpecial Paste:=xlPasteFormats
                Range("A1").EntireRow.Delete
                
                'Refigure our last row
                    LastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Offset(-1, 0).Row
                
                'Fill in the blanks in columns A through B with the value above
                    Range("A3:B" & LastRow).SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
                'Columns("A:B").Value = Columns("A:D").Value
                    Columns("A:B").Copy
                    Columns("A:B").PasteSpecial Paste:=xlValues, Operation:=xlNone, _
                    SkipBlanks:=False, Transpose:=False
                
                'Create the lookup column
                Range("A1").EntireColumn.Insert
                'Plug in the formula
                Range("A2:A" & LastRow).FormulaR1C1 = "=RC[1]&RC[2]&RC[3]"
            End With 'Done with the Worksheets sheet
            
            'Now let's bring in the values from the Play pivot to our projections
            TwoB.Sheets("MFR Adjustments").Activate
            
            With TwoB.Sheets("MFR Adjustments")
                'Refigure our last row
                LastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Offset(-1, 0).Row
                Range("E1").FormulaR1C1 = "Current MFR Projection"
                Range("E2:E" & LastRow).FormulaR1C1 = _
                    "=IF(ISNA(VLOOKUP(RC[-4]&RC[-3]&RC[-2],Worksheet!C[-4]:C[3],8,FALSE)),0,VLOOKUP(RC[-4]&RC[-3]&RC[-2],Worksheet!C[-4]:C[3],8,FALSE))"
                Range("F1").FormulaR1C1 = "MFR Adjustments"
                Range("F2:F" & LastRow).FormulaR1C1 = "=RC[-2]-RC[-1]"
                  
                'Find last column
                LastCol = Range("IV5").End(xlToLeft).Column
                With Application.WorksheetFunction
                
                'Place column totals in row after current last row
                    For iCol = 5 To LastCol 'Starting in column E
                        Cells(LastRow + 1, iCol) = .Sum(Range(Cells(1, iCol), Cells(LastRow, iCol)))
                    Next iCol
                End With
                Columns("A:F").EntireColumn.AutoFit
                Columns("D:F").Style = "Comma"
            End With 'Done with the MFR Adjustments sheet
           
            'Now let's save this puppy where it needs to be
            Application.DisplayAlerts = False
            Dim MO As Variant, HO As Variant
            Set MO = TwoB.Sheets("Lookups").Range("H1")
            Set HO = TwoB.Sheets("Lookups").Range("M1")
            
            
            Run "SaveIt"
            
    '        TwoB.SaveAs FileName:= _
    '            "\\12AUST1001FS01\SHARE10011\Budget\SOBUDGET\CPS\MFR Projections\2011\Current\" & HO.Value & " MFR Projection for " & MO.Value & ".xls", FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
    '            ReadOnlyRecommended:=False, CreateBackup:=False
            
            'Clean up
            Run "Delete2BDeleted"
            'Start showing if there are any problems
            'Application.DisplayAlerts = True
        
            'Let Allison know it's ready
            Run "Sendmail"
            
            'Now we save it to our desktop
            Application.DisplayAlerts = False
            Dim DTAddress As String
            Dim WshShell As Object
            Set WshShell = CreateObject("WScript.Shell")
            DTAddress = CreateObject("WScript.Shell").SpecialFolders("Desktop") & Application.PathSeparator
            ActiveWorkbook.SaveAs DTAddress & ActiveWorkbook.Name
            Application.DisplayAlerts = True
            
            'Return the focus to excel
            AppActivate "Microsoft Excel"
            
            MsgBox "The projection file has been saved to your desktop and to" & vbCrLf & vbCrLf & _
                    "S:\Budget\SOBUDGET\CPS\MFR Projections\2011\Current" & vbCrLf & vbCrLf & _
                    "Please review to identify variances and items of concern."
                    
            Workbooks("MFR Projection Tool.xls").Close False 'We're done.
     
        End With 'this turns screen updating back on
    End Sub
    Sub SaveIT()
    Set TwoB = Workbooks("2BDeleted.xls")
            'Now let's save this puppy where it needs to be
            Application.DisplayAlerts = False
            Dim MO As Variant, HO As Variant
            Set MO = TwoB.Sheets("Lookups").Range("H1")
            Set HO = TwoB.Sheets("Lookups").Range("M1")
           
            ActiveWorkbook.SaveAs HO & " MFR Projection for " & MO & ".xls", FileFormat:=xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False
    
    
            Application.DisplayAlerts = True
    End Sub
    Last edited by jomili; 07-25-2011 at 08:54 AM.

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,978

    Re: Excel shutting down during save

    A couple of immediate questions/observations:
    1. Why are you using Run rather than calling the code directly?
    2. There's a lot of unnecessary selecting, activating and unqualified Range statements in there.
    3. What are the values of HO and MO?

  7. #7
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    4,056

    Re: Excel shutting down during save

    1) Self-taught in VBA, so blame my teacher that I don't know the right code to use. What do you mean by "Call directly", rather than "Run"?

    2) You'd have to point out specifics for me to explain the "why"s of these.

    3)
    Dim MO As Variant, HO As Variant
            Set MO = TwoB.Sheets("Lookups").Range("H1")
            Set HO = TwoB.Sheets("Lookups").Range("M1")
    TwoB is the workbook that contains the Lookups sheet I attached to my first post. HO and MO are in there.

  8. #8
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    4,056

    Re: Excel shutting down during save

    Run or Call;
    I just did some research, and it appears you use Run when you're calling a macro from another workbook, Call when you're running a macro within a workbook. All of my macros are run from one workbook, and they all modify another workbook, and use other workbooks. So that's why I use Run.

  9. #9
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,978

    Re: Excel shutting down during save

    If the code is all in the same workbook, you don't use Run, regardless of which workbook is being modified. If you do use Run, you should specify the workbook that the code is in.

  10. #10
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    4,056

    Re: Excel shutting down during save

    For 1), are you saying I could just put Killbutts, with nothing else, and "Killbutts()" would run?

    For 2, you're right. I had thought
     With TwoB.Sheets("Worksheet").Range("A1")
    would cover all of the code under it until my "End With", but my WITH is only talking about A1, not the other cells. Sloppy of me; I'll work on that.

    For 3, I don't remember what values were in the workbook I first posted, as they change depending on what month we're in a what region we're running. Representative values are June for H1, 030 for M1.

  11. #11
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,978

    Re: Excel shutting down during save

    1. I mean:
    Killbutts
    rather than:
    Run "Killbutts"
    2. For example here:
    Range("A3:B" & LastRow).SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
    you would be better off explicitly stating which sheet is being used. The odd thing is that sometimes you do it and others you don't - such as in this part:
            With TwoB.Sheets("Worksheet").Range("A1")
                .PasteSpecial Paste:=xlPasteValues
                .PasteSpecial Paste:=xlPasteFormats
                Range("A1").EntireRow.Delete
                
                'Refigure our last row
                    LastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Offset(-1, 0).Row
    where you have two fully qualified Range references, one unqualified one, then one qualified only with Activesheet.

    3. That doesn't tell me what the values are.

  12. #12
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,978

    Re: Excel shutting down during save

    1. Yes. You can also use
     Call Killbutts
    but it is unnecessary.

    Do you have any code in the BeforeSave event as a matter of interest?

  13. #13
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    4,056

    Re: Excel shutting down during save

    No, nothing before save. Would it help if I posted the workbook that all of my code is in? A lot of it wouldn't run, as it depends on other workbooks, but you're welcome to inspect the code if you'd like.

  14. #14
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,978

    Re: Excel shutting down during save

    Feel free - though if it's a lot of code I can't guarantee when I can look through it.

  15. #15
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    4,056

    Re: Excel shutting down during save

    It's getting worse. When my active workbook (TwoB) is created, it's automatically saved to my desktop. So, I added a routine right before my attempted save to the new drive, to save the active workbook, no name change or anything. Excel crashed again, no error message other than Excel is attempting to save my work. The code I used to save my workbook is simply
    ActiveWorkbook.Save
    . I use it successfully in previous macros, but at the point in question it causes Excel to crash.

    I've attached my workbook containing all of my code in the hope that someone can pinpoint the problem. As it stands now, ActiveWorkbook.Save works in the "Lookups" macro, but fails in the "Finish" macro. Any help is greatly appreciated.
    Attached Files Attached Files

  16. #16
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    4,056

    Re: Excel shutting down during save

    Okay, I've narrowed it down more. ActiveWorkbook.Save works BEFORE "Killbutts", but ActiveWorkbook.Save immediately after "Killbutts" causes Excel to fail. So, I'm thinking "Killbutts" might be the problem, I just don't know why. If I remove Killbutts, it runs flawlessly.

    Here's "Killbutts"; it's purpose is to delete some autoshape buttons on the active sheet. It seems to work well, but something's going wonky with it.
    Sub Killbutts()
    'Activate sheet to delete autoshapes.
    Dim GetShape As Shape
        For Each GetShape In ActiveSheet.Shapes
            GetShape.Delete
        Next
        With ActiveSheet
        'Return our rows to normal
                Rows("1:8").RowHeight = 15
        'Remove the Color and words from our range
                Range("C1:F7").ClearContents
                Range("C1:F7").Interior.ColorIndex = xlNone
        End With
    End Sub
    BTW, Killbutts grew from this post: http://www.excelforum.com/excel-prog...-coloring.html

  17. #17
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,978

    Re: Excel shutting down during save

    My initial impression is that your workbook is corrupt as it keeps leaving shadow copies of itself open in the VBE (though it doesn't crash when I save it). My earlier points still apply though, and you ought to use Thisworkbook to refer to the workbook running the code, rather than hardcoding its name into the code.

  18. #18
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,978

    Re: Excel shutting down during save

    Comment out the shape delete, then test it again.

  19. #19
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    4,056

    Re: Excel shutting down during save

    Running it like this, everything works fine (except my buttons aren't deleted):
    Sub Killbutts()
    'Activate sheet to delete autoshapes.
    'Dim GetShape As Shape
        'For Each GetShape In ActiveSheet.Shapes
            'GetShape.Delete
        'Next
        With ActiveSheet
        'Return our rows to normal
                Rows("1:8").RowHeight = 15
        'Remove the Color and words from our range
                Range("C1:F7").ClearContents
                Range("C1:F7").Interior.ColorIndex = xlNone
        End With
    End Sub

  20. #20
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,978

    Re: Excel shutting down during save

    How about if you use:
    Sub Killbutts()
    'Activate sheet to delete autoshapes.
    Dim GetShape As Button
        For Each GetShape In ActiveSheet.Buttons
           GetShape.Delete
        Next GetShape
        With ActiveSheet
        'Return our rows to normal
                Rows("1:8").RowHeight = 15
        'Remove the Color and words from our range
                Range("C1:F7").ClearContents
                Range("C1:F7").Interior.ColorIndex = xlNone
        End With
    End Sub

  21. #21
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    4,056

    Re: Excel shutting down during save

    That works, no Excel failure. It deletes my two buttons, but it doesn't delete the two red rectangular autoshapes I had behind my two buttons.

  22. #22
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,978

    Re: Excel shutting down during save

    Try replacing the loop with:
    activesheet.drawingobjects.delete
    and see if that does it. It's generally not a good idea to just delete all shapes on a sheet, especially if you have autofilters, data validation and the like on it.

  23. #23
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,978

    Re: Excel shutting down during save

    Glad to help. All good fun, isn't it?

  24. #24
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    4,056

    Re: Excel shutting down during save

    Sure. Except for all my hair falling out, a nervous giggle whenever I speak, and the twitching of the whole left side of my face, I'm having the time of my life!

  25. #25
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,978

    Re: Excel shutting down during save

    Only the left side? Give it time.

    Oh, and please don't forget to mark Solved. Ta.

+ 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