Hi,
I'm currently trying to create a master list of prices of a product that changes from day to day. In order to do this more efficiently, I want to write a macro that will pull data from the daily workbook (always formatted in the same way eg: 31 Jan 2013.xlsx) that I download to a specific path every morning. Once the data has been pulled, I want the workbook to close and be moved to an archive folder. I have tried various codes that I've found on here for the file opening. I understand that I have to write something that will take Date and search for it in DD MMM YYYY format and loop it while subtracting 1 day from it each time. Here is the code I am using so far for the file opening:
Sub Macro1()
'
' Macro1 Macro
'
Dim TheString As String, TheDate As Date
Dim ThePath As String, TheBook As Workbook
Set TheBook = ThisWorkbook
TheDate = Date
ThePath = "C:\Daily Prices\"
TheString = WorksheetFunction.Text(TheDate, "DD MMM YYYY") & ".xlsx"
On Error Resume Next
Do
Workbooks.Open ThePath & TheString
If Err <> 0 Then
TheDate = Date - 1
TheString = WorksheetFunction.Text(TheDate, "DD MMM YYYY") & ".xlsx"
Err = 0
Else
On Error GoTo 0
Exit Do
End If
Loop Until ActiveWorkbook.Name <> ThisWorkbook.Name
'
End Sub
The code above seems to get stuck in the loop and can not open the file. I typically only have one file in the folder (the current day) so I can adjust it to work exclusively for the current day, but I get these prices sometimes on a Sunday and I'll have to do Date - 1 on Monday. Can someone help me fix this one?
Also will need help with how to refer to the opened file once it's been opened as my data pulling macro pulls from over 10 different groups of cells so the code switches the Active workbook back and forth between the master and the daily. Finally the file moving as well to path: C:\Daily Prices\Archived.
Sorry for the long post, I want to make sure I cover all the bases in one post.
Bookmarks