Skip to content

Instantly share code, notes, and snippets.

@okayamadaiti
Created November 19, 2020 09:55
Show Gist options
  • Save okayamadaiti/ae2cdd368cb44764de541c4ce129a3c1 to your computer and use it in GitHub Desktop.
Save okayamadaiti/ae2cdd368cb44764de541c4ce129a3c1 to your computer and use it in GitHub Desktop.
スライドをコピーしつつPDFオブジェクトを差し込む
Option Explicit
' スライドにファイルオブジェクトを追加する
Sub addFile(ByRef sl As SlideRange, ByVal fileName As String)
sl.Shapes.AddOLEObject(Left:=10, Top:=10, Width:=390, Height:=520, fileName:=fileName, Link:=msoFalse).Select
End Sub
' マスターとなるシート(最初のシート)を末尾にコピーする
Function copyMasterSheet() As SlideRange
Dim newSlide As SlideRange
Set newSlide = ActivePresentation.Slides(1).Duplicate
newSlide.MoveTo toPos:=ActivePresentation.Slides.Count
Set copyMasterSheet = newSlide
End Function
' マスターシートをコピーしつつ、指定フォルダ内のファイルを追加する
' 任意のDirectoryPath を指定すること。
Sub addPdfs()
Const DirectoryPath As String = "C:\Users\username\Desktop\新しいフォルダー\"
Dim tempSlide As SlideRange
Dim buf As String
buf = Dir(DirectoryPath)
Do While buf <> ""
Set tempSlide = copyMasterSheet
ActiveWindow.View.GotoSlide Index:=ActivePresentation.Slides.Count
Call addFile(tempSlide, DirectoryPath + buf)
buf = Dir()
Loop
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment