Stefan Braem
New Member
- Joined
- Jun 23, 2021
- Messages
- 5
Hi
I'm trying to open another workbook based on the day of the week extracted from the date in the file name of the current workbook. This is my code:
When I let it run, I get an Error 5 (Invalid procedure call of argument) but I can't seem to find out why. The error appears at the line indicated in red. Could someone help me on this?
Thanks in advance!
I'm trying to open another workbook based on the day of the week extracted from the date in the file name of the current workbook. This is my code:
Code:
Function OpenWerkboek()
Dim Bestand As String
Dim DatumDag As Long
Dim DatumMaand As Long
Dim DatumJaar As Long
Dim Datum As Date
Dim Dag As String
Dim Pad As String
Dim Werkboek As Workbook
Bestand = ThisWorkbook.FullName
DatumDag = CLng(Mid(Bestand, Len(Bestand) - 6, -2))
DatumMaand = CLng(Mid(Bestand, Len(Bestand) - 8, -2))
DatumJaar = CLng(Mid(Bestand, Len(Bestand) - 12, -4))
Datum = DateSerial(DatumJaar, DatumMaand, DatumDag)
Dag = Weekday(Datum)
Pad = "C:\Users\stefa\Downloads\LOGBOEK 2021 (vanaf Juli)\03 WERKROOSTERS\" & Dag & ".xlsm"
Werkboek = Workbooks.Open(Pad)
End Function
When I let it run, I get an Error 5 (Invalid procedure call of argument) but I can't seem to find out why. The error appears at the line indicated in red. Could someone help me on this?
Thanks in advance!