Opening password protected PPT in VB

D

djerinic

I woud like to open password protected PPT from vb6. I found code (see
below) that run in PPT (code is saved as macro and I started macro),
but doesn't work if I place it in VB module. Can anybody help me!

Thanks, Dak


Code:

Option Explicit
Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal
nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As
Long
Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal
nIDEvent As Long) As Long
Public TimerID As Long
Public sPwd As String

Sub OpenPassPres()
Dim objPPT As PowerPoint.Application
Dim objPres As PowerPoint.Presentation
Set objPPT = New PowerPoint.Application
objPPT.Visible = msoTrue

TimerID = SetTimer(0, 0, 2000, AddressOf PassProc)
' Replace with your password
sPwd = "q"
' Replace C:\Test.ppt with your path to presentation
Call Presentations.Open("C:\Test.ppt")
End Sub

Sub PassProc(ByVal hwnd As Long, _
ByVal uMsg As Long, _
ByVal idEvent As Long, _
ByVal dwTime As Long)
TimerID = KillTimer(0, TimerID)
SendKeys sPwd & "~"
End Sub
 
S

Shyam Pillai

The code was designed to run in the PPT environment and not from VB.
Sendkeys is sent to the active window. So you will need to ensure that the
password dialog is the window in the foreground when sendkeys is sent. A
more reliable approach will be to get the handle of the Password window
textbox and use SendMessage to send the password to it.


--
Regards,
Shyam Pillai

Toolbox
http://skp.mvps.org/toolbox
 
D

dak

Hi,

This is usefull information. But I am new in Windows API so I don't now
how to get the handle of the Password window textbox and how to use
SendMessage. Can you write me code for this (what I have to change in
my code) or send me any usefull link about this.

Thanks,

Dak

Shyam Pillai je napisao:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top