I am running a macro from an excel file called "MASTER - FX Reconciliations Modelvista.xls" (excel 2010 in compatibility mode to save in 2003 format) from a button in the spreadsheet. The macro takes data from a file called "rollifrp.x ls" (after a small amount of manipulation) and pastes it into the
"MASTER - FX Reconciliations Modelvista.xls" file. It then attempts to save the rollifrp file down with a new name dependent on the content of cells E4 and E6 on the Index tab of the "MASTER - FX Reconciliations Modelvista.xls" file. This renaming and saving is NOT successful - I get a run time error 1004 "document not saved". When I then debug and choose the run to cursor option and run the macro to the end it does exactly what I want it to. Why do I get the run time error and how can I get rid of it - it is driving me mad!! I've checked out the microsoft site but the content did not seem relevant. The code is below - any help greatly appreciated!
"MASTER - FX Reconciliations Modelvista.xls" file. It then attempts to save the rollifrp file down with a new name dependent on the content of cells E4 and E6 on the Index tab of the "MASTER - FX Reconciliations Modelvista.xls" file. This renaming and saving is NOT successful - I get a run time error 1004 "document not saved". When I then debug and choose the run to cursor option and run the macro to the end it does exactly what I want it to. Why do I get the run time error and how can I get rid of it - it is driving me mad!! I've checked out the microsoft site but the content did not seem relevant. The code is below - any help greatly appreciated!
Code:
Sub FXcurr()
Application.ScreenUpdating = False
Dim stDocName As String
Dim stDocName2 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
' Copy data to master file
Range("A:L").Select
Selection.Copy
Windows("MASTER - FX Reconciliations Modelvista.xls").Activate
Sheets("rollifrp").Select
Range("A1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
' Reformat original file for saving in AP folders
Windows("rollifrp.xls").Activate
Sheets("Sheet1").Select
ActiveSheet.Range("A:L").Select
Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Range("A1").Select
If AP.Value < 10 Then
stDocName2 = "Q:\Reports\Financial Reporting\IFRS\" & CurrYr & "\AP0" & AP.Value & "\04_Models\rollifrp AP0" & AP.Value & ".xls"
Else
stDocName2 = "Q:\Reports\Financial Reporting\IFRS\" & CurrYr & "\AP" & AP.Value & "\04_Models\rollifrp AP" & AP.Value & ".xls"
End If
ActiveWorkbook.SaveAs stDocName2
Comment