Hello again! After modifying codes from various sources, below are the 2 versions of VBA Macro in PowerPoint that solved my problem:
1. Copies all JPG files in one folder and paste it in separate PPT Slides
Sub CreatePictureSlideshow()
'Copy VBA in PowerPoint
Dim presentation
Dim layout
Dim slide
Dim FSO
Dim folder
Dim file
Dim folderName
' Set this to point at the folder you wish to import JPGs from
' Note: make sure this ends with a backslash \
folderName = "D:\Some Directory\"
' Delete all slides and setup variables
Set presentation = Application.ActivePresentation
If presentation.Slides.Count > 0 Then
presentation.Slides.Range.Delete
End If
Set layout = Application.ActivePresentation.SlideMaster.CustomLayouts(1)
Set FSO = CreateObject("Scripting.FileSystemObject")
' Retrieve the folder's file listing and process each file
Set folder = FSO.GetFolder(folderName)
For Each file In folder.Files
' Filter to only process JPG images
If LCase(Mid(file.Name, Len(file.Name) - 3, 4)) = ".jpg" Then
' Create the new slide and delete any pre-existing contents
Set slide = presentation.Slides.AddSlide(presentation.Slides.Count + 1, layout)
While slide.Shapes.Count > 0
slide.Shapes(1).Delete
Wend
' Add the picture
slide.Shapes.AddPicture folderName + file.Name, False, True, 10, 10
' Optional: create a textbox with the filename on the slide for reference
' Dim textBox
' Set textBox = slide.Shapes.AddTextbox(msoTextOrientationHorizontal, 10, 10, 200, 200)
' textBox.TextFrame.TextRange.Text = file.Name
End If
Next
End Sub
2. Copies all RTF files in one folder and paste it in separate PPT Slides
Sub CreateRTFSlideshow()
'Copy VBA in PowerPoint
Dim presentation
Dim layout
Dim slide
Dim FSO
Dim folder
Dim file
Dim folderName
' Set this to point at the folder you wish to import RTFs from
' Note: make sure this ends with a backslash \
folderName = "D:\Some Directory\"
' Delete all slides and setup variables
Set presentation = Application.ActivePresentation
If presentation.Slides.Count > 0 Then
presentation.Slides.Range.Delete
End If
Set layout = Application.ActivePresentation.SlideMaster.CustomLayouts(1)
Set FSO = CreateObject("Scripting.FileSystemObject")
' Retrieve the folder's file listing and process each file
Set folder = FSO.GetFolder(folderName)
For Each file In folder.Files
' Filter to only process RTF files
If LCase(Mid(file.Name, Len(file.Name) - 3, 4)) = ".rtf" Then
' Create the new slide and delete any pre-existing contents
Set slide = presentation.Slides.AddSlide(presentation.Slides.Count + 1, layout)
While slide.Shapes.Count > 0
slide.Shapes(1).Delete
Wend
' Add the picture
'slide.Shapes.AddPicture folderName + file.Name, False, True, 10, 10
Dim WordApp As Object
Set WordApp = CreateObject("Word.Application")
With WordApp
'Change file name to suit
.Documents.Open FileName:=folderName + file.Name
.ActiveDocument.Select
.Selection.Copy
End With
With Slide.Shapes.PasteSpecial(ppPasteMetafilePicture)
.Align msoAlignCenters, True
.Align msoAlignMiddles, True
.Item(1).ScaleHeight 2, msoCTrue, msoScaleFromMiddle
End With
' Optional: create a textbox with the filename on the slide for reference
' Dim textBox
' Set textBox = slide.Shapes.AddTextbox(msoTextOrientationHorizontal, 10, 10, 200, 200)
' textBox.TextFrame.TextRange.Text = file.Name
End If
Next
End Sub
Hope this helps!
Bookmarks