I want to create code that will open up an excel workbook that has a different name every week. In the file path it is "we 11-08-14" I want to be able to open that folder up and select a filename based on wildcard values included around the day I want to access. This is what I have so far. It is compiling it successfully but it won't open the document. I suspect an error in the directory.
Sub ImportOpenWK()
Dim directory As String
Dim fileName As String
Dim foldername As String
Dim sheet As Worksheet
Dim total As Integer
Dim weeknum As Integer
Dim dayser As Long
Dim weekof As Long
Dim convertser As Date
Dim wbk As Workbook
Application.ScreenUpdating = False
Application.DisplayAlerts = False
weeknum = Format$(Now(), "ww", vbSaturday)
dayser = DateSerial(2014, 1, 4)
weekof = dayser - 7 + 7 * weeknum
convertser = weekof
convertser = Format$(weekof, "mm-dd-yy")
directory = "S:\District\WP\All\H2K\Planning\Plans\Lineups\we&convertser"
fileName = Dir(directory & "Monday Lineup??")
Do While fileName <> ""
Set wbk = Workbooks.Open(directory & fileName)
wbk.Worksheets("Imported Data").Range("A2:N10000").Copy
Worksheets("This Week SP").Range("A2").PasteSpecial (xlPasteValues)
Application.CutCopyMode = False
Workbooks(fileName).Close
fileName = Dir()
Loop
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
Bookmarks