I am trying to open an Excel spreadsheet within a changing location. The variables are the dates and file name:
C:\Reports\2019\09. September 2019\10 September 2019\1. Client reports\Report_20190911.csv
I have tried using variables, referencing to specific cells within a workbook to add the dates that are changing on a daily, monthly, and yearly basis.
Example:
Today - C:\Reports\2019\09. September 2019\10 September 2019\1. Client reports\Report_20190911.csv
Tomorrow - C:\Reports\2019\09. September 2019\11 September 2019\1. Client reports\Report_20190912.csv
I cannot seem to add an image of my referenced excel cells so I will describe it (all the cells are formula driven for the date):
Cell B4 - 10/09/2019
Cell B6 - 2019
Cell B7 - 09. September 2019
Cell B9 - 10 September 2019
Below is my code:
Sub Client_Reports()
Dim year_ As Integer
year_ = Cells(6, 2)
Dim month_ As String
month_ = Cells(7, 2)
Dim date_ As Date
date_ = Cells(9, 2)
Dim FilePath As String
Dim FileName As String
FileName = "Report_"& Format(Range("B4") + 1, "yyyymmdd") & ".csv"
FilePath = "C:\Reports\year_\month_\date_\1. Client reports\FileName"
Workbooks.Open (FilePath)
End Sub
It searches for C:\Reports\year_\month_\date_\1. Client reports\Report_20190911.csv