• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1780
  • Last Modified:

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

I'm using the presentations.open 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 presentations.open method?

Thanks for your help,

1
bentleyousley
Asked:
bentleyousley
  • 2
  • 2
1 Solution
 
osmodeanCommented:
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.Password

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

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"
        .Save
        .Close
    End With
End Sub

I hope this helps!

Osmodean
0
 
bentleyousleyAuthor Commented:
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
                oPPTPres.SlideShowSettings.Run
            Else
                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
    Else
        MsgBox "The code failed to instantiate PowerPoint session.", _
                vbCritical + vbOKOnly, "PowerPoint Automation Example"
    End If
End Sub
0
 
osmodeanCommented:
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!

Osmodean
0
 
bentleyousleyAuthor Commented:
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,
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now