Dear experts,
I'm still a beginner in VBA, and only capable of doing cut & paste works to make my own macro.
I've completed the whole macro (which will call up another macro), but if I press F5 (from within the VBA Project) the codes can call up another macro and complete to the end. However if I press the macro hotkey (Ctrl+shift+o), it will stop before the line calling up another macro). I now list below my codes for your checking & advice :
Sub OpenCF_File()
'Open each Project Cashflow file, and Copy from Monthly Cashflow Report (for new month cashflow) to this Project Cashflow file
'
'Ctrl+ Shft + O
'
Dim MyFiles As String
Dim CurrentFolder As String
Dim FileName As String
Dim myPath As String
Dim UniqueName As Boolean
UniqueName = False
Application.AskToUpdateLinks = False
Application.DisplayAlerts = False
MyFiles = Dir(ActiveWorkbook.Path & "\*Cashflow.xl*")
Do While MyFiles <> ""
Workbooks.Open ActiveWorkbook.Path & "\" & MyFiles
Call CopyPCF
ActiveWorkbook.Close SaveChanges:=True
On Error GoTo 0
MyFiles = Dir
Loop
Application.AskToUpdateLinks = True
Application.DisplayAlerts = True
Exit Sub
End Sub
Sub CopyPCF()
'
' Insert new Cashflow Month with linkage to new month of CFR file
'
' Ctrl+ Shft + P
'
Workbooks(2).Activate
Dim P_Code As String
Dim Dtl_Sheet As String
P_Code = Range("PCode")
Dtl_Sheet = Range("DtlSheet")
Workbooks(1).Activate
Dim CashflowWB As String
CashflowWB = ActiveWorkbook.Name
Workbooks(1).Sheets(Dtl_Sheet).Select
Rows("9:9").Select
Selection.Find(What:=P_Code, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, MatchByte:=False, SearchFormat:=False).Select
ActiveCell.EntireColumn.Select
Workbooks(2).Activate
Columns("E:F").Select
Selection.Copy
Selection.Insert Shift:=xlToRight
Range("E1") = CashflowWB
Range("E6") = "=+EOMONTH(G6,1)"
Range("E6").Copy
Range("E6").PasteSpecial Paste:=xlPasteValues 'Date : avoid EOMONTH error for 2003
Columns("D:D").Select
Selection.Replace What:=Range("G1"), Replacement:=Range("E1"), LookAt:=xlPart _
, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("CI").Select
Selection.Copy
ActiveCell.Offset(0, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues
Range("CO_COST").Select
Selection.Copy
ActiveCell.Offset(0, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues
Range("CO_PAYABLE").Select
Selection.Copy
ActiveCell.Offset(0, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues
ActiveCell.Offset(10, 0).Select
End Sub
Thanks in advance
Edward
Bookmarks