PDA

View Full Version : [SOLVED:] PPT VBA to Insert Slides via ReUse Slides



gmooney100
06-15-2021, 09:31 AM
I have some code that is giving me a RUn time Error: Slides (unknown member): Failed

It happens on this line:
ActivePresentation.Slides.InsertFromFile _FileDownload, 1, 1, 26




Sub Finish()


Dim URL1 As String
Dim URL2 As String
Dim TextFile As Integer
Dim FilePath As String
Dim FileContent As String
Dim FileDownload As String
Dim i As Long


'PURPOSE: Send All Data From Text File To A String Variable


'File Path of Text File
FilePath = GetDownloadsPath & "\" & "Category Review BUCategory.txt"


'Determine the next file number available for use by the FileOpen function
TextFile = FreeFile


'Open the text file
Open FilePath For Input As TextFile


'Store file content inside a variable
FileContent = Input(LOF(TextFile), TextFile)


'Close Text File
Close TextFile

FileDownload = GetDownloadsPath & "\" & FileContent & ".pptx"


ActivePresentation.Slides.InsertFromFile _
FileDownload, 1, 1, 26

'Delete Text File
Kill FileDownload
End Sub



Any ideas how to correct?

John Wilson
06-15-2021, 01:09 PM
What is the GetDownloadPath ??

gmooney100
06-15-2021, 01:29 PM
Sorry about that John...

Function GetDownloadsPath() As String

GetDownloadsPath = Environ$("USERPROFILE") & "\Downloads"


End Function

gmooney100
06-15-2021, 03:05 PM
What is the GetDownloadPath ??

John,

Here is the GetDownloadsPath Function:



Function GetDownloadsPath() As String

GetDownloadsPath = Environ$("USERPROFILE") & "\Downloads"


End Function


I did just discover if I replace FileDownload from ActivePresentation.Slides.InsertFromFile FileDownload, 1, 1, 26 with the actual hard coded file path and name the error goes away so know I think I have a problem with my GetDownloadsPath?

John Wilson
06-15-2021, 11:27 PM
The only thing that jumps out as a possible problem.

Where you say 'Delete Text File
You are actually deleting the pptx I think. Maybe it is being killed before it has fully reused the slides. I'm presuming there are 26 slides to insert.

gmooney100
06-16-2021, 11:16 AM
I have commented out the Delete Text File and I still have the issue. If I debug and hover over


FileContent = Input(LOF(TextFile), TextFile) I get FileContent = "Category Review Grand Canyon - Packaged Beverages. Notice the leading quote but no ending quote. However, if I open the immediate window and do ? FileContent I get Category Review Grand Canyon - Packaged Beverages without any quotes.

Could this be the issue?

John Wilson
06-16-2021, 12:54 PM
Are you sure that is the Downloads folder??

For me it's
getDownloadsPath = Environ("USERPROFILE") & "\Documents\Downloads"

Apart from that the code works for me but of course I cannot see what you have in the text file. Are there quotes there?