Hello all,
I'm trying to modify my code in order to close a workbook after it's served its purpose. I've placed the code below. I'm currently receiving a Compile error: Type mismatch. The file I'm opening has "CHARTER_REPLEN" in the name, but it also has a date stamp before the portion of the consistent name "CHARTER_REPLEN" that is always in the name.
All help is always appreciated.
D.
I'm trying to modify my code in order to close a workbook after it's served its purpose. I've placed the code below. I'm currently receiving a Compile error: Type mismatch. The file I'm opening has "CHARTER_REPLEN" in the name, but it also has a date stamp before the portion of the consistent name "CHARTER_REPLEN" that is always in the name.
Rich (BB code):
Sub OpenMostRecent()
Dim fso As FileSystemObject, folder As Object
Dim wPath As String, wMax As Long, wFile As Variant, wf As Variant
wPath = "C:\Users\DVelez202\Desktop\VBA Code Files"
Set fso = CreateObject("scripting.FileSystemObject")
Set folder = fso.getfolder(wPath)
Set wfiles = folder.Files
wMax = 0
wFile = ""
For Each wf In wfiles
ext = Mid(wf.Name, InStrRev(wf.Name, ".") + 1)
If LCase(ext) Like "*xlsx*" Then
If wf.DateLastModified > wMax Then
wMax = wf.DateLastModified
wFile = wf.Name
End If
End If
Next
If wFile <> "" Then Workbooks.Open wFile
End Sub
Sub CopyNeg()
Dim OldWb As Workbook
Dim NewWb As Workbook
Dim NewWs As Worksheet
Dim CurWs As Worksheet
Set OldWb = "C:\Users\DVelez202\Desktop\VBA Code Files\_CHARTER_REPLEN"
Set CurWs = ActiveWorkbook.Worksheets("Replen Report")
Set NewWb = Workbooks.Add
Set NewWs = NewWb.Sheets(1)
CurWs.Range("A:T").AutoFilter Field:=20, Criteria1:="<0"
CurWs.AutoFilter.Range.EntireRow.Copy
NewWs.Range("A1").PasteSpecial xlPasteValuesAndNumberFormats
NewWb.SaveAs "C:\Users\DVelez202\Desktop\VBA Code Files\Negative Replenishment file_" _
& Format(Date, "mm.dd.yyyy") & ".xlsx", FileFormat:=51
OldWb.Close
End Sub
All help is always appreciated.
D.