I am trying to copy specific cells from a file from the day before and paste them on the same spot in my current workbook as text.
I only want this to be done on Thursday.
Sub OpenFile()
If Weekday(Now()) = vbThursday Then
FileYear = Year(Date)
FileDate = Format(Date, "yymmdd")
FilePath = "I:\Example\2020\" & Format(Now() - 1, "yymmdd") & " " & _
"Sequentieanalyse werkblad.xlsm"
Workbooks.Open (FilePath)
Range("P48:Z57").Select
Selection.Copy
ActiveWorkbook.Close False
Sheets("Monsterlijst").Select
Range("P48:Z57").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End If
End Sub
When I run my code I get a messagebox that there is a lot of information on the clipboard and I have to select yes, no or abort, followed by a runtime error 1004 with either of the options.
When I use Application.DisplayAlerts = False
I also get a Runtime error 1004.
There are no error messages when I remove ActiveWorkbook.Close False
, but my info will paste back in the workbook I am copying from instead of in my current workbook.
I also want the file from the previous day closed to prevent confusion.
The copy part does works, because if I cancel the error message I can paste it manually.
How would I adapt the code to run on Friday instead of Thursday if Thursday is a bank holiday?