• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Copy multiple external files into one compiled file

tbalcom

New Member
This question is actually just a question about VBA code for a macro in PPT. I have about 76 different PPT files that are one slide each and need to compile them into one single PPT and the seperate files are always changing so I would like a macro to access the external files, copy and paste them together into one new file. I have code that now that accesses a .txt file with all the links to these files and it will open them and compile them now but it will not carry over any of the formatting or layout, just the words. Does anyone know what the issue could be? I have put the code I have now below:


Sub InsertFromList()

' Inserts all presentations named in LIST.TXT into current presentation

' in list order

' LIST.TXT must be properly formatted, one full path name per line


On Error GoTo ErrorHandler


Dim sListFileName As String

Dim sListFilePath As String

Dim iListFileNum As Integer

Dim sBuf As String


' EDIT THESE AS NEEDED

' name of file containing files to be inserted

sListFileName = "list.TXT"


' backslash terminated path to folder containing list file:

sListFilePath = "-instert path the .txt file containing links to files-"


' Do we have a file open already?

If Not Presentations.Count > 0 Then

Exit Sub

End If


' If LIST.TXT file doesn't exist, create it

If Len(Dir$(sListFilePath & sListFileName)) = 0 Then

iListFileNum = FreeFile()

Open sListFilePath & sListFileName For Output As iListFileNum

' get file names

sBuf = Dir$(sListFilePath & "*.PPT")

While Not sBuf = ""

Print #iListFileNum, sBuf

sBuf = Dir$

Wend

Close #iListFileNum

End If


iListFileNum = FreeFile()

Open sListFilePath & sListFileName For Input As iListFileNum

' Process the list

While Not EOF(iListFileNum)

' Get a line from the list file

Line Input #iListFileNum, sBuf


' Verify that the file named on the line exists

If Dir$(sBuf) <> "" Then

Call ActivePresentation.Slides.InsertFromFile( _

sBuf, ActivePresentation.Slides.Count)

End If

Wend


Close #iListFileNum

MsgBox "Complete"


NormalExit:

Exit Sub

ErrorHandler:

Call MsgBox("Error:" & vbCrLf & Err.Number & vbCrLf & Err.Description, _

vbOKOnly, "Error inserting files")

Resume NormalExit

End Sub
 
Back
Top