Ramadan
Board Regular
- Joined
- Jan 20, 2024
- Messages
- 113
- Office Version
- 2021
- Platform
- Windows
I have found a code and modified it to perform my need which is to cycle the drop down list in a sheet and save the filtered data as PDFs in external folder with the currant date after the file name. but because the curranet date is changable of course, the folder still keeping the last time saved files and I have to delete them manually - what I need please is to edit the code to clear the destination folder from the old saved files before saving the new files or to Override each file with the new one
here is my code... any Suggestions please
here is my code... any Suggestions please
VBA Code:
Sub myFiles()
Dim wb As Workbook
Dim ws As Worksheet
Dim nwb As Workbook
Dim nws As Worksheet
Dim rng As Range
Dim Path As String
Dim myDate As String
Set wb = ThisWorkbook
Set ws = wb.Worksheets("Print")
Set rng = ws.Range("B2")
Path = "D:\Desktop\Docs\"
myDate = Format(Now(), "DD-MM-YYYY")
For i = 1 To 5
rng = ws.Range("A" & i)
ws.Copy
Set nwb = ActiveWorkbook
Set nws = nwb.Worksheets("Print")
With nws
Cells.Copy
Cells.PasteSpecial (xlPasteValues)
End With
Application.DisplayAlerts = False
nwb.ExportAsFixedFormat Type:=xlTypePDF, filename:=Path & ws.Range("c2") & " " & myDate
nwb.Close
Application.DisplayAlerts = True
Next i
End Sub