Friday, September 15, 2023

All Excel Files from Folder Save as PDF

 All Excel Files from Folder Save as PDF




Sub Excel_File_SaveasPDF()
Dim SaveLocation As String
Dim bookList As Workbook
Dim mergeObj As Object, dirObj As Object, filesObj As Object, everyObj As Object
Application.ScreenUpdating = False
Set mergeObj = CreateObject("Scripting.FileSystemObject")
 '
'change folder path of excel files here

SaveLocation = Worksheets("Main").Cells(6, 3).Value
Dim FDialog As FileDialog
    
    Set FDialog = Application.FileDialog(msoFileDialogFolderPicker)
    
    If FDialog.Show = -1 Then

        Worksheets("Main").Cells(6, 3).Value = FDialog.SelectedItems(1)

    End If

Set dirObj = mergeObj.Getfolder(Worksheets("Main").Cells(6, 3).Value)
Set filesObj = dirObj.Files
For Each everyObj In filesObj
Set bookList = Workbooks.Open(everyObj)
bookList.Activate
bookList.ExportAsFixedFormat xlTypePDF, Filename:=SaveLocation & "\" & everyObj.Name & ".pdf"

bookList.Close
Next

Sheets("Main").Activate

MsgBox ("PDF File Generated")

End Sub





'   END OF CODE






No comments:

Post a Comment

Headline Animator

Parmod Kumar Gupta

Subscribe via email

Enter your email address:

SAKSHI

You Might Also Like

Related Posts with Thumbnails