View Full Version : PowerPoint VBA Array Issue - Slides (unknown member): Failed
SpikeTTS
04-24-2016, 08:11 PM
Can someone please look at my code and tell me why I keep getting this error?
Slides (unknown member): Failed
Here's my code: Any help is greatly appreciated!
(I get the error above from inside the For loop on the line: sPres.Slides.InsertFromFile ListBoxContents(Y), sPres.Slides.Count).
' ListBoxContents is a pre-filled array with three elements containing other PowerPoint filenames - I'm trying to merge the three files into an existing presentation (sPres).
Dim sPres As Presentation
Set sPres = ActivePresentation
With sPres
For Y = 0 To UBound(ListBoxContents)
sPres.Slides.InsertFromFile ListBoxContents(Y), sPres.Slides.Count
Next
End With
John Wilson
04-24-2016, 11:59 PM
Can you post the actual content of ListBoxContents(0)
SpikeTTS
04-25-2016, 08:02 AM
Yes John. Here's what is in the array ListBoxContents(): It can one to many .pptx filenames. I transfer these filenames from a listbox on userform to the array. Thank you so much for your attention and help.
BAB_Tag Up_2016 03 22 (Mar 22 2016) Accomplishments.pptx
BAB_Tag Up_2016 03 22 (Mar 22 2016) Agenda.pptx
BAB_Tag Up_2016 03 22 (Mar 22 2016) Arch & Concepts.pptx
BAB_Tag Up_2016 03 22 (Mar 22 2016) Battle Rhythm Weekly.pptx
BAB_Tag Up_2016 03 22 (Mar 22 2016) Safety.pptx
BAB_Tag Up_2016 03 22 (Mar 22 2016) Title.pptx
BAB_Tag Up_2016 03 22 (Mar 22 2016) Tools.pptx
John Wilson
04-25-2016, 08:14 AM
You need to provide the full path not just the name.
SpikeTTS
04-25-2016, 09:28 AM
John, below is the code where I added the fullpath to the filename. Unfortunately, I got the same error. I did notice something before that I didn't mention -- it will insert all the files and then crash at the end of the operation at the same line: sPres.Slides.InsertFromFile ListBoxContents(Y), sPres.Slides.Count
Private Sub PopulateArray()
Size = Me.lst_selectedfields.ListCount - 1
ReDim ListBoxContents(0 To Size) As String
Dim I, x, Y As Integer
'populate selected listbox names to array
For I = 0 To UBound(ListBoxContents)
ListBoxContents(I) = srcPath & "\" & Me.lst_selectedfields.List(I)
Next I
End Sub
John Wilson
04-26-2016, 12:03 AM
Sounds like somehow the last member f the array is not a valid address (or blank) Try adding a debug print to see what each member holds
'populate selected listbox names to array
For I = 0 To UBound(ListBoxContents)
debug.print I & ">>" & ListBoxContents(I)
ListBoxContents(I) = srcPath & "\" & Me.lst_selectedfields.List(I)
Next I
SpikeTTS
04-26-2016, 06:48 AM
Thank you John! You solved it -- you were right -- I was picking up a blank additional array element which generated the error! The blank array element was passed to the sPres.Slides.InsertFromFile ListBoxContents(Y), sPres.Slides.Count line of code and it threw an exception because it was blank. :beerchug:
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.