Hello everyone. I have the following ( a bit if an ongoing project) VBA code (below posted) I ahve been working on. I would like to declare my workbooks as objects. Worksheeets as objects also, if necessary. I have been told that it will improve performance and make for cleaner code. Any suggestions wopuld be appreciated.
Sub Macro1()
Const sPath1 As String = "L:\12_31_2009_157_Reports\"
Const sPath2 As String = "L:\12_31_2009_105_Support_Summaries\"
Const SFileInp1 As String = "105xls_version 5.xls"
Const SFileInp2 As String = "Formulas.xlsm"
Const sFileOut1 As String = "12_31_2009_Data.xlsm"
Workbooks.Add
With ActiveSheet
.Name = "12_31_2009_105_Data"
.Parent.SaveAs Filename:=sPath1 & sFileOut1, _
FileFormat:=xlOpenXMLWorkbookMacroEnabled, _
CreateBackup:=False
.Parent.Close
End With
Workbooks.Open Filename:=sPath1 & SFileInp1
Range("A4:Z50000").Copy
Workbooks.Open Filename:=sPath2 & SFileInp2
With ActiveSheet
.Range("A1").PasteSpecial
.Name = "105_12_31_2009_version1"
Range("C1").Value = "Book_ID"
Range("E1").Value = "Deal_ID"
Range("F1").Value = "Instrument_ID"
Range("G1").Value = "Trade_Type"
Range("H1").Value = "Security_ID"
Range("I1").Value = "Trade_ID"
Range("J1").Value = "PR_Flag"
Range("K1").Value = "Amortized_Cost_USD_12/31/2009"
Range("L1").Value = "MTM_USD_12/31/2009"
Range("M1").Value = "Unrealized_P/L_USD_12/31/2009"
Range("N1").Value = "Amortized_Cost_USD_11/31/2009"
Range("O1").Value = "MTM_USD_11/31/2009"
Range("P1").Value = "Unrealized_P/L_USD_11/31/2009"
Range("Q1").Value = "Amortized_Cost_USD"
Range("R1").Value = "MTM_USD"
Range("S1").Value = "Unrealized_PL_USD"
Range("T1").Value = "Initial_Notional_USD"
Range("U1").Value = "Notional_Exchange"
Range("V1").Value = "Maturity_Date"
Range("W1").Value = "Trade_Date"
Range("X1").Value = "Settlement_Date"
Range("Y1").Value = "Expected Maturity_Yrs"
Range("Z1").Value = "Expected_Maturity_Date"
End With
ActiveWorkbook.Close SaveChanges:=True
End Sub
Sub Macro2()
Const sPath1 As String = "L:\12_31_2009_157_Reports\"
Const sPath2 As String = "L:\12_31_2009_105_Support_Summaries\"
Const SFileInp1 As String = "Formulas.xlsm"
Const SFileInp2 As String = "12_31_2009_Data.xlsm"
Workbooks.Open Filename:=sPath2 & SFileInp1
Range("A1:AV50000").Copy
Workbooks.Open Filename:=sPath1 & SFileInp2
Range("A1").PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, _
SkipBlanks:=False, _
Transpose:=False
End Sub
Sub Main()
Application.ScreenUpdating = False
Call Macro1
Call Macro2
Application.ScreenUpdating = False
End Sub
Bookmarks