m_vishal_c
Board Regular
- Joined
- Dec 7, 2016
- Messages
- 209
- Office Version
- 365
- 2016
- Platform
- Windows
Hi I have 52 .PNG files in one folder and i want to convert into pdf by macro in same folder. can anyone suggest me. thanks in advance
Sub SavePNGtoPDF()
Dim NewSheet As Worksheet
Set FSO = CreateObject("Scripting.FileSystemObject")
Set MyFolder = FSO.GetFolder("C:\TestFolder")
For Each MyFile In MyFolder.Files
If LCase(Right(MyFile.Name, 3)) = "png" Then
Set NewSheet = Sheets.Add
NewSheet.PageSetup.PaperSize = xlPaperA4
NewSheet.Range("A1").Activate
Set MyPic = NewSheet.Pictures.Insert(MyFolder & "\" & MyFile.Name)
NewSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=MyFolder & "\" & Left(MyFile.Name, Len(MyFile.Name) - 4) & ".pdf"
End If
Next
Set MyPic = Nothing
Set NewSheet = Nothing
Set MyFolder = Nothing
Set FSO = Nothing
End Sub
Sub SavePNGtoPDF()
Dim NewSheet As Worksheet
Set FSO = CreateObject("Scripting.FileSystemObject")
Set MyFolder = FSO.GetFolder("C:\TestFolder")
For Each MyFile In MyFolder.Files
If LCase(Right(MyFile.Name, 3)) = "png" Then
Set NewSheet = Sheets.Add
NewSheet.PageSetup.PaperSize = xlPaperA4
NewSheet.Range("A1").Activate
Set MyPic = NewSheet.Pictures.Insert(MyFolder & "\" & MyFile.Name)
NewSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=MyFolder & "\" & Left(MyFile.Name, Len(MyFile.Name) - 4) & ".pdf"
Application.DisplayAlerts = False
NewSheet.Delete
Application.DisplayAlerts = True
End If
Next
Set MyPic = Nothing
Set NewSheet = Nothing
Set MyFolder = Nothing
Set FSO = Nothing
End Sub