I have an excel 97-2003 file called "MASTER - FX Reconciliations Modelvista.xls" that I open using Excel 2010. Within this file I run a VBA macro with the name FXcurr. This macro picks up a file called rollifrp.xls (97-2003 Worksheet) makes some amendments to it and then saves it down to a file path detarmined by the entries in two cells of the MASTER - FX Reconciliations Modelvista.xls file. The macro errors and returns a "Document not saved" "Run time error 1004" message. When I debug I can run past the errro using the "run to cursor" option - this then saves down the file as per the the code insructions, saving down the rollifrp.xls file in the right location as a 97-2003 file (we are set to run in compatibility mode). How do I get rid of the error message that appears - as I don't want to have to keep having to debug, go into the code select a line beyond the error and run to cursor each time. This has been driving me crazy - if you could help that would be great!
The problem line within the code is this part:
The problem line within the code is this part:
Code:
Windows("rollifrp.xls").Activate Columns("A:L").Select Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlGuess, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom If AP.Value < 10 Then stDocName = "Q:\Reports\Financial Reporting\IFRS\" & CurrYr & "\AP0" & AP.Value & "\04_Models\rollifrp AP0" & AP.Value & ".xls" Else stDocName = "Q:\Reports\Financial Reporting\IFRS\" & CurrYr & "\AP" & AP.Value & "\04_Models\rollifrp AP" & AP.Value & ".xls" End If Windows("rollifrp.xls").Activate Range("A1").Select ActiveWorkbook.SaveAs stDocName ******ERRORS HERE SAYING DOCUMENT NOT SAVED****** ActiveWorkbook.Close The full code for the macro is below: Sub FXcurr() ' ' FXcurr Macro ' Macro recorded 19/04/2006 by u415264 ' ' Open Quantum download report Application.ScreenUpdating = False Dim stDocName As String Dim AP As Range Dim CurrYr As Range Application.ScreenUpdating = False Set AP = Worksheets("Index").Range("E4") Set CurrYr = Worksheets("Index").Range("E6") ' rollifrp excel details only stDocName = "Q:\Reports\Financial Reporting\IFRS\Models\rollifrp.xls" Workbooks.Open stDocName Windows("rollifrp.xls").Activate Cells.Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlCenter .WrapText = True .Orientation = 0 .AddIndent = False .ShrinkToFit = False .MergeCells = False End With Rows("1:10").Select Selection.Delete shift:=xlToUp Columns("F:F").Select Selection.Delete shift:=xlToLeft Columns("G:G").Select Selection.Delete shift:=xlToLeft Columns("H:H").Select Selection.Delete shift:=xlToLeft Columns("L:L").Select Selection.Delete shift:=xlToLeft Range("B2").Select Selection.Cut Range("B1").Select ActiveSheet.Paste Range("G1").Select Selection.Cut Range("H1").Select ActiveSheet.Paste Range("B1").Select Selection.Copy Range("I1").Select ActiveSheet.Paste Range("I2:J2").Select Selection.Cut Range("J1").Select ActiveSheet.Paste Range("K2").Select Selection.Cut Range("L1").Select ActiveSheet.Paste Range("L2").Select Selection.Cut Range("M1").Select ActiveSheet.Paste Rows("2:4").Select Selection.Delete shift:=xlToUp ' ActiveSheet.Shapes("Picture -767").Select ' Selection.Cut ' Copy data to master file Cells.Select Selection.Copy Windows("MASTER - FX Reconciliations Modelvista.xls").Activate Sheets("rollifrp").Select ActiveSheet.Paste ' Reformat original file for saving in AP folders Windows("rollifrp.xls").Activate Columns("A:L").Select Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlGuess, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom If AP.Value < 10 Then stDocName = "Q:\Reports\Financial Reporting\IFRS\" & CurrYr & "\AP0" & AP.Value & "\04_Models\rollifrp AP0" & AP.Value & ".xls" Else stDocName = "Q:\Reports\Financial Reporting\IFRS\" & CurrYr & "\AP" & AP.Value & "\04_Models\rollifrp AP" & AP.Value & ".xls" End If Windows("rollifrp.xls").Activate Range("A1").Select ActiveWorkbook.SaveAs stDocName ******ERRORS HERE SAYING DOCUMENT NOT SAVED****** ActiveWorkbook.Close