Consulting

Results 1 to 2 of 2

Thread: Can't regain control of PP after form unloads

  1. #1
    VBAX Regular
    Joined
    Sep 2007
    Posts
    18
    Location

    Can't regain control of PP after form unloads

    I am a pretty advanced computer user, but my VBA skills are crude at best. I'm running Office 2010 on a Windows 7 machine.

    I have a macro in PowerPoint 2010 that loads a form. On the form are two list windows and 3 buttons. One button just re-initializes the form (labeled "Start Over") and another just unloads the form (labeled "Done"). The main action button (labeled "Create Slides") allows me to create a presentation by merging several smaller presentations.

    My problem is that after I click the main action button, while the presentation slides are created successfully, the macro (or userform) does not give me back control of PowerPoint--I can't click anywhere in the ribbon bar to perform any tasks. If I run the macro with the VBA editor open and at the conclusion of the macro I go back to the editor and click the "Reset" button, I get control of PowerPoint again.

    Here's the basic code:

    This is the macro that loads the form:
    [vba]
    Sub Make_Slides()
    frmCreateSlides.Show
    End Sub
    [/vba]

    This is the "Start Over" button:
    [vba]
    Private Sub cbStartOver_Click()
    lbFileList.Clear
    lbWednesdaySongs.Clear
    iSelectCount = 0
    Call UserForm_Initialize
    End Sub
    [/vba]

    This is the "Done" button:
    [vba]
    Private Sub cbDone_Click()
    Unload Me
    End Sub
    [/vba]

    The initialization routine fills a listbox with a list of smaller PPTX files. By double-clicking a file name, it is transferred to the other listbox which is then used as the source for the files to merge. All of that activity works just fine the problem is with the code for the "Create Slides" button, shown below.

    This is the "Create Slides" button:
    [vba]
    Private Sub cbCreateSlides_Click()
    Dim sPath As String
    sPath = "C:\Users\...\Files"
    Dim sFileName As String
    Dim sDate As String
    Dim iListCount As Integer
    Dim oDonor As Presentation
    Dim otarget As Presentation
    Dim i As Integer, j As Integer
    For i = 4 To 1 Step -1
    ActivePresentation.Slides(i).Delete
    Next i
    On Error GoTo errhandler
    On Error Resume Next
    sDate = CStr(Date)
    sDate = Replace(sDate, "/", "-")
    ChDir (sPath)

    iListCount = lbWednesdaySongs.ListCount
    Set otarget = ActivePresentation
    For i = 0 To iListCount - 1
    sFileName = lbWednesdaySongs.List(i)
    Set oDonor = Presentations.Open(sFileName, msoFalse)
    For j = 1 To oDonor.Slides.Count
    oDonor.Slides(j).Copy
    With otarget.Slides.Paste(otarget.Slides.Count + 1)
    .Design = oDonor.Slides(j).Design
    .ColorScheme = oDonor.Slides(j).ColorScheme
    End With
    Next j
    oDonor.Close
    Set oDonor = Nothing
    Next i
    Unload Me
    errhandler:
    ' MsgBox ("There is a problem somewhere")
    Exit Sub
    End Sub
    [/vba]

    Even before I added the line "Unload Me" the form would disappear from view after merging the files and I would not be able to access any PowerPoint commands or menus. The same is true even after I inserted the "Unload Me" line.

    If, on the first time I run the macro, I click the "Done" button, the form goes away and I can work with PowerPoint just fine. Also, during the first running of the macro, if I get part way through my file selection and want to start over, the "Start Over" button works just fine.

    However, if I run the macro, create the new presentation, stop it via the reset button in the VBA editor and then try to run the macro again, my form comes up with nothing in the listboxes and the "Done" and "Start Over" buttons no longer work.

    Thank you in advance for your help!

    Bruce

  2. #2
    VBAX Regular
    Joined
    Sep 2007
    Posts
    18
    Location
    After some more investigation, I have discovered these two things:

    1) After the macro runs, if I click away from PowerPoint to another open app and then click back to PowerPoint, I have control of it (PowerPoint) again and can freely use the ribbon bar, etc.

    2) By stepping through the macro, I find it seem to hang on this line:
    [VBA]oDonor.Slides.Count[/VBA]

    Am I doing something wrong in the way I determine the slide count?

    Bruce

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •