Dear all
I tried to create a code that will open a workbook. I don't want to use the exact file location, but instead, I want to work with a reference to a date in a particular cell.
So e.g. I need to open a file called 'Test_20160630_V2'. Because I will need to do this every month, I don't want to copy/paste the exact file location every month, but I want to include a reference to the particular date, in this case 30/06/2016.
So YYYY returns 2016, MM 06 and DD 30.. Do I need to convert it to string, because Excel doesn't find the file.
I tried to create a code that will open a workbook. I don't want to use the exact file location, but instead, I want to work with a reference to a date in a particular cell.
So e.g. I need to open a file called 'Test_20160630_V2'. Because I will need to do this every month, I don't want to copy/paste the exact file location every month, but I want to include a reference to the particular date, in this case 30/06/2016.
Code:
Sub Test()
Dim Test As Worksheet
Dim wbB As Workbook
Dim YYYY As String
Dim MM As String
Dim DD As String
Dim DatReport As Range
Set DatReport = ActiveWorkbook.Worksheets("Test").Range("B2")
YYYY = Format(DatReport, "yyyy")
MM = Format(DatReport, "mm")
DD = Format(DatReport, "dd")
Set wbB = Workbooks.Open("F:\TestMcTest\Test_report\YYYY\YYYYMMDD\2_TestieTest\Test_YYYYMMDD_V2.xls")
End Sub
So YYYY returns 2016, MM 06 and DD 30.. Do I need to convert it to string, because Excel doesn't find the file.