PDA

View Full Version : [SOLVED:] Can't get userform to stay active



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

SamT
10-08-2014, 04:32 PM
I believe that it is the use of the ActiveWindow Object in the code.

Try setting the UserForm's Visible Property to True at the end of the Button Click sub.

bwwhite
10-09-2014, 07:08 AM
SamT,

Thanks for the suggestion. It would not allow me to use the visible property of my userform. I get the error message "Function or interface marked as restricted, or the function uses an Automation type not supported in Visual Basic".

Bruce

SamT
10-09-2014, 09:24 AM
Was the only change to the sub was to add, as the last line in the code;

Me.Visible = True

bwwhite
10-10-2014, 05:06 AM
SamT,

I added that line and got that same error message I posted earlier. If I tried Me.Show or Me.Repaint, I got no error message, but my userform still disappeared. Any other thoughts?

I also added this line in my errorhandling:

If Err Then MsgBox Err.Description, vbCritical, "Error"

When I do that along with Me.Visible = True, I get the same old error message. But when I use Me.Show, I now get the message "Form already displayed; can't show modally". I've also tried showing it with mode 0 and mode 1 after the initial loading and in this sub.

Bruce

bwwhite
10-10-2014, 05:52 AM
Finally got my code to work properly.

Got an idea from this location:
http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_28402531.html

I added "vbModeless" after my initial .Show of the form. Then in the code that was giving me problems, I added this statement:

If Not Me.Visible Then Me.Show vbModeless

Now the code works fine!

Thanks!

Bruce

PS--I thought there was a special way to mark this solved, but could not find it, so I just put "[SOLVED]" in the title line.

SamT
10-10-2014, 07:04 AM
PPS: LOL:

Yeah, in Thread Tools there is a "Mark Thread Solved" Box.

I am glad your problem is solved.

FYI, there is a UserForm Mode Property you can set at Design Time.