jason1000rr
New Member
- Joined
- Sep 2, 2016
- Messages
- 14
Hi Everyone
Looking for some help to close the workbook after code is executed. It's a bit lengthy, so if you see some room for improvement as well, please do tell
Looking for some help to close the workbook after code is executed. It's a bit lengthy, so if you see some room for improvement as well, please do tell
Code:
Dim MyPath As String
Dim MyFile As String
Dim LatestFile As String
Dim LatestDate As Date
Dim LMD As Date
Dim ws As Worksheet
Sheets("IQR").Select
Columns("A:AL").Select
Selection.ClearContents
Range("A1").Select
MyPath = "\\global.corp.net\site\Procurement\IQR"
If Right(MyPath, 1) <> "\" Then MyPath = MyPath & "\"
MyFile = Dir(MyPath & "*.xlsx", vbNormal)
If Len(MyFile) = 0 Then
MsgBox "No files were found...", vbExclamation
Exit Sub
End If
Do While Len(MyFile) > 0
LMD = FileDateTime(MyPath & MyFile)
If LMD > LatestDate Then
LatestFile = MyFile
LatestDate = LMD
End If
MyFile = Dir
Loop
Workbooks.Open MyPath & LatestFile
For Each ws In ActiveWorkbook.Worksheets
If ws.Name Like "*20*" Then ws.Select
Next ws
ActiveSheet.Cells.Copy
For Each wb In Application.Workbooks
If wb.Name Like "*Kanban Calculator*" Then wb.Activate
Next wb
Range("A1").Select
ActiveSheet.Paste