bwwhite
10-08-2014, 01:16 PM
I have a userform in PowerPoint that I use the add slides from multiple PPTX files into an open dummy file.
The userform functions as follows:
There are 4 radio buttons on the form, each of which specify a different path to the files. This selection is made before anything else is done with the userform. Once the selection is made, a subroutine is run that displays a list of all the files in the chosen folder in a window on the left-hand side of the form.
Once that left-hand window is filled with file names, the user can double-click any file name to move it to a window on the right-hand side of the form. This window will then contain a list of files to merge. A file can be removed from the right-hand window and put back in the left-hand window by double-clicking it.
Once the correct files are chosen, a button labeled "Create Slides" can be clicked. The code in this button is where I'm having an issue. I can run the code in this button just fine, but after running the code, my userform disappears but I want it to remain active. Not only does it disappear, but I can't activate any menu commands in PowerPoint unless I first click somewhere outside of PowerPoint and then click back in.
The code in "Create Slides" opens files, copies their slides into the "master" presentation, and then closes the file. I've narrowed things down to the fact that when it closes the file from which slides are copied, that's when the userform closes. The only way to make "Create Slides" work, is by using a line of "On Error Resume Next" which I know doesn't really fix the error.
How can I close the "donor" file but keep the userform open?
I'm attaching the code for "Create Slides". If I need to attach the .pptm file, I can do that if needed. I'm hoping something might be obvious in the code I've attached.
Thank you in advance!
Bruce
Private Sub cbCreateSlides_Click()
Dim sFileName As String
Dim sDate As String
Dim iListCount As Integer
Dim oDonor As Presentation
Dim oTarget As Presentation
Dim oSlides As Slides
Dim oSlide As Slide
Dim i As Integer
Dim j As Integer
On Error Resume Next
sDate = CStr(Date)
sDate = Replace(sDate, "/", "-")
ChDir (sPath & "Slides\")
Dim lngCSI As Long 'CSI = current slide index
ActiveWindow.ViewType = ppViewSlideSorter
ActiveWindow.ViewType = ppViewNormal
lngCSI = ActiveWindow.View.Slide.SlideIndex
iListCount = lbWednesdaySongs.ListCount
Set oTarget = ActivePresentation
For i = 0 To iListCount - 1
lngCSI = ActiveWindow.View.Slide.SlideIndex
sFileName = lbWednesdaySongs.List(i)
Set oDonor = Presentations.Open(sFileName, msoFalse)
Set oSlides = oDonor.Slides
j = 1
For Each oSlide In oSlides
oDonor.Slides(j).Copy
With otarget.Slides.Paste(oTarget.Slides.Count + 1)
.Design = oDonor.Slides(j).Design
.ColorScheme = oDonor.Slides(j).ColorScheme
End With
j = j + 1
Next oSlide
oDonor.Close
Next i
Set oDonor = Nothing
For i = 4 To 1 Step -1
oTarget.Slides(i).Delete
Next i
End Sub
The userform functions as follows:
There are 4 radio buttons on the form, each of which specify a different path to the files. This selection is made before anything else is done with the userform. Once the selection is made, a subroutine is run that displays a list of all the files in the chosen folder in a window on the left-hand side of the form.
Once that left-hand window is filled with file names, the user can double-click any file name to move it to a window on the right-hand side of the form. This window will then contain a list of files to merge. A file can be removed from the right-hand window and put back in the left-hand window by double-clicking it.
Once the correct files are chosen, a button labeled "Create Slides" can be clicked. The code in this button is where I'm having an issue. I can run the code in this button just fine, but after running the code, my userform disappears but I want it to remain active. Not only does it disappear, but I can't activate any menu commands in PowerPoint unless I first click somewhere outside of PowerPoint and then click back in.
The code in "Create Slides" opens files, copies their slides into the "master" presentation, and then closes the file. I've narrowed things down to the fact that when it closes the file from which slides are copied, that's when the userform closes. The only way to make "Create Slides" work, is by using a line of "On Error Resume Next" which I know doesn't really fix the error.
How can I close the "donor" file but keep the userform open?
I'm attaching the code for "Create Slides". If I need to attach the .pptm file, I can do that if needed. I'm hoping something might be obvious in the code I've attached.
Thank you in advance!
Bruce
Private Sub cbCreateSlides_Click()
Dim sFileName As String
Dim sDate As String
Dim iListCount As Integer
Dim oDonor As Presentation
Dim oTarget As Presentation
Dim oSlides As Slides
Dim oSlide As Slide
Dim i As Integer
Dim j As Integer
On Error Resume Next
sDate = CStr(Date)
sDate = Replace(sDate, "/", "-")
ChDir (sPath & "Slides\")
Dim lngCSI As Long 'CSI = current slide index
ActiveWindow.ViewType = ppViewSlideSorter
ActiveWindow.ViewType = ppViewNormal
lngCSI = ActiveWindow.View.Slide.SlideIndex
iListCount = lbWednesdaySongs.ListCount
Set oTarget = ActivePresentation
For i = 0 To iListCount - 1
lngCSI = ActiveWindow.View.Slide.SlideIndex
sFileName = lbWednesdaySongs.List(i)
Set oDonor = Presentations.Open(sFileName, msoFalse)
Set oSlides = oDonor.Slides
j = 1
For Each oSlide In oSlides
oDonor.Slides(j).Copy
With otarget.Slides.Paste(oTarget.Slides.Count + 1)
.Design = oDonor.Slides(j).Design
.ColorScheme = oDonor.Slides(j).ColorScheme
End With
j = j + 1
Next oSlide
oDonor.Close
Next i
Set oDonor = Nothing
For i = 4 To 1 Step -1
oTarget.Slides(i).Delete
Next i
End Sub