Hello. I don't use macros often (once every few years) but have a need for one now. I have a folder which houses individual monthly files (at year end there will be one for each month, so in theory one is added monthly), there is also a summary file. The example code below is for May and Jun but it'll contain all 12 months. Note, the following works fine if the files exist and all are open. I'd like for the macro to check to see if a file is open and if so, run the macro. In other words, if running it today for the month of Jul and the Jul file is open, it would copy and paste to the summary file... and not error-out on non-existent future months or prior month's files that are not open (i.e., Jan - Jun and Aug - Dec). Additionally, if a file is not open when attempting to run the macro I'd like for a 'Monthly File Not Open' message to appear. Thanks in advance for any assistance.
Sub Test()
'
' Test Macro
fname = Dir("C:\Users\name\OneDrive - BB\Comparison\wrike - 656\*.xlsx")
If fname Like ("[05.]*") Then
Workbooks("05.2021 Monthly Comparison.xlsx").Worksheets("Summary").Range("B7:B12").Copy
Workbooks("Comparison Year to Date Summary 2021.xlsm").Worksheets("Summary").Range("E8").PasteSpecial Paste:=xlPasteValues
Workbooks("05.2021 Monthly Comparison.xlsx").Worksheets("Summary").Range("C15:C16").Copy
Workbooks("Comparison Year to Date Summary 2021.xlsm").Worksheets("Summary").Range("E17").PasteSpecial Paste:=xlPasteValues
If fname Like ("[06.]*") Then
Workbooks("06.2021 Monthly Comparison.xlsx").Worksheets("Summary").Range("B7:B12").Copy
Workbooks("Comparison Year to Date Summary 2021.xlsm").Worksheets("Summary").Range("F8").PasteSpecial Paste:=xlPasteValues
Workbooks("06.2021 Monthly Comparison.xlsx").Worksheets("Summary").Range("C15:C16").Copy
Workbooks("Comparison Year to Date Summary 2021.xlsm").Worksheets("Summary").Range("F17").PasteSpecial Paste:=xlPasteValues
End If
End If
End Sub
Sub Test()
'
' Test Macro
fname = Dir("C:\Users\name\OneDrive - BB\Comparison\wrike - 656\*.xlsx")
If fname Like ("[05.]*") Then
Workbooks("05.2021 Monthly Comparison.xlsx").Worksheets("Summary").Range("B7:B12").Copy
Workbooks("Comparison Year to Date Summary 2021.xlsm").Worksheets("Summary").Range("E8").PasteSpecial Paste:=xlPasteValues
Workbooks("05.2021 Monthly Comparison.xlsx").Worksheets("Summary").Range("C15:C16").Copy
Workbooks("Comparison Year to Date Summary 2021.xlsm").Worksheets("Summary").Range("E17").PasteSpecial Paste:=xlPasteValues
If fname Like ("[06.]*") Then
Workbooks("06.2021 Monthly Comparison.xlsx").Worksheets("Summary").Range("B7:B12").Copy
Workbooks("Comparison Year to Date Summary 2021.xlsm").Worksheets("Summary").Range("F8").PasteSpecial Paste:=xlPasteValues
Workbooks("06.2021 Monthly Comparison.xlsx").Worksheets("Summary").Range("C15:C16").Copy
Workbooks("Comparison Year to Date Summary 2021.xlsm").Worksheets("Summary").Range("F17").PasteSpecial Paste:=xlPasteValues
End If
End If
End Sub