Powerpoint "password" dialog box suspending execution of VB code when attempting to populate the password via sendkeys

Posted on 2005-04-30
1 Endorsement
Last Modified: 2008-01-09
I'm using the method to launch a PowerPoint presentation within VB6. I wish to automatically fill-in the password dialog box that pops-up when launching a password protected .ppt. I received a previous suggestion on another thread to find and bring into focus the dialog box and then use sendkeys to populate the password.

The problem is: when the password dialog box is presented, the VB app stops executing any other commands until the dialog box is dismissed. I've tried using timers to get around this problem, but the timers also pause until the password dialog box is dismissed. Any suggestions to make this happen? Anyway around pausing the execution? Alternately, is there a way to pass the password within (or appended to) the method?

Thanks for your help,

Question by:bentleyousley
    LVL 6

    Expert Comment

    Password Property
    See Also Applies To  

    Returns or sets a String that represents a password that must be supplied to open the specified presentation. Read/write.


    expression   Required. An expression that returns one of the objects in the Applies To list.

    This example opens Earnings.ppt, sets a password for it, and then closes the presentation.

    Sub SetPassword()
        With Presentations.Open(FileName:="C:\My Documents\Earnings.ppt")
            .Password = "why"
        End With
    End Sub

    I hope this helps!


    Author Comment

    Thank you for your response, Osmodean.

    I understand what you are suggesting and had previously seen an example similar to this in the PPT documentation. I don't understand what specific code I would need to add in order to allow my application to automatically specify the password for PPT.

    Attached is the subroutine I'm currently using. Perhaps I might get you to point out specifically what I would need to change in order to make this work.

    The issue now is: when the "Set oPPTPres = .Presentations.Open(PresPath, , , False)" line is performed the password dialog appears and the VB application doesn't execute any other instructions until it is dismissed. I haven't found a way to set the .password property within this code sucessfully. I look forward to your comments.

    Thanks again,

    Sub AutomatePowerPoint()  
        On Error Resume Next
        Set oPPTApp = CreateObject("PowerPoint.Application")
        If Not oPPTApp Is Nothing Then
            Set oPPTAppEvents = New PowerPoint.Application
            With oPPTApp
                Set oPPTPres = .Presentations.Open(PresPath, , , False)
                If Not oPPTPres Is Nothing Then
                    MsgBox "The code could not open the specified file." & _
                            "Check if the file is present at the location.", _
                            vbCritical + vbOKOnly, "PowerPoint Automation Example"
                End If
            End With
            MsgBox "The code failed to instantiate PowerPoint session.", _
                    vbCritical + vbOKOnly, "PowerPoint Automation Example"
        End If
    End Sub
    LVL 6

    Accepted Solution

    The problem is the following:
    Visual Basic is a single threaded application, this means that you cant put a certain procedure on hold and proceed with another (in the same application).
    When powerpoint has an "on open"-password set, the CreateObject procedure inside your application is put on hold untill powerpoint releases it, this is when the user types in a password.
    There is no way around this that I know off, but you can make a workaround:

    Make 2 applications, 1 application is the application you already have, the second one is a "powerpoint unlocker".
    You run the second program just before you open the protected powerpoint presentation in application 1.
    You can do that with the shell command.
    The "powerpoint unlocker" can be as advanced as you want it to be, you can for example provide command line parameters to specify which presentation must be unlocked with what password.
    Then you use the findwindow api to get the window handle of the locked presentation. Once you have that, you use the sendmessage api to input the password.
    After this the "powerpoint unlocker" unloads and the first application can resume with its excution.

    I hope this helps!


    Author Comment

    At first I didn’t think this was going to work. I had a stand alone application which found the handle of the password dialog box and then used sendkeys to populate the password. After multiple attempts, out of frustration I launched the ‘unlock’ app multiple times consecutively. The PPT unlocked and ran. I knew it must have something to do with timing so a put a sleep command before both the ‘handle finder’ and the sendkeys statement and … Taa …Daa: it worked great.

    Thanks for your help with this,

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now