Dear Experts,
I've problems modifying below codes as they codes cannot finish to the end :
1. I've in folder many project files for current month and last month
2. Each file name has a standard format like 02015-201909-Flex*.xlsm (this month), and 02015-201908-Flex*.xlsm (last month), while * refers to any further characters that may be added for some particular files.
3. I wish the codes to open each pair of project files (this month then last month), and execute another macro to copy from 201908 file to 201909 file
4. However the codes stop in the middle
Would like if anyone could help.
Many thanks.
I've problems modifying below codes as they codes cannot finish to the end :
1. I've in folder many project files for current month and last month
2. Each file name has a standard format like 02015-201909-Flex*.xlsm (this month), and 02015-201908-Flex*.xlsm (last month), while * refers to any further characters that may be added for some particular files.
3. I wish the codes to open each pair of project files (this month then last month), and execute another macro to copy from 201908 file to 201909 file
4. However the codes stop in the middle
Code:
Sub OpenFlexO_and_FlexN()
'Open each project's Flex file (This Month), and then corresponding project's Flex file (Last Month), and perform copying from Flex (Last Month) to Flex (This Month)
'
'Ctrl+ b
'
Application.AskToUpdateLinks = False
Application.DisplayAlerts = False
Dim MyFlexFiles As String
Dim MyFlexOldFiles As String
Dim CurrentFolder As String
Dim FileName As String
Dim myPath As String
Dim UniqueName As Boolean
CMth = Range("O6")
LMth = Range("Q6")
UniqueName = False
'Store Information About Excel File
MyFlexFiles = Dir(ActiveWorkbook.Path & "\" & "?????-" & CMth & "-Flex*.xlsm")
MyFlexOldFiles = Dir(ActiveWorkbook.Path & "\" & "?????-" & LMth & "-Flex*.xlsm")
Do While MyFlexFiles <> "" Or MyFlexOldFiles <> ""
myPath = ActiveWorkbook.FullName
CurrentFolder = ActiveWorkbook.Path & "\"
FileName = Mid(myPath, InStrRev(myPath, "\") + 1, InStrRev(myPath, ".") - InStrRev(myPath, "\") - 1)
ProjectCode = Mid(FileName, 1, 5)
YearMth = Mid(FileName, 7, 6)
'Open current month Flex file first
Workbooks.Open ActiveWorkbook.Path & "\" & MyFlexFiles
'Then Open last month Flex file
Workbooks.Open ActiveWorkbook.Path & "\" & MyFlexOldFiles
Call Copy_Lmth
On Error GoTo 0
MyFlexFiles = Dir
MyFlexOldFiles = Dir
Loop
Application.AskToUpdateLinks = True
Application.DisplayAlerts = True
MsgBox "Done : Copy This Mth to Last Mth in Transaction Worksheet"
Exit Sub
End Sub
Would like if anyone could help.
Many thanks.