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
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.
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.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks