Opening PPT using VB programing

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi there

Can anybody help me in finding out a way to open PPT thru VB programing for a open pwd/readonly pwd PPTs. The following open statement in my VB code is not opening the PPT read-only mode automatically. Instead it is prompting for entering (or selection of readonly) password. I would like to know how to avoid the 'promptin for pwd panel' to open the ppt in readonly automatically. Also want to know how to trap the 'open pwd' set ppt

PptApp.Presentations.Open(frmPath.List4.List(filecount), msoTrue, msoTrue, msoFalse

Ta
K. Rajasekar
 
The PowerPoint Object model does not expose any interface to open password
protected files programatically. The only know workaround is to make use of
SendKeys.

--
Regards
Shyam Pillai

http://www.mvps.org/skp

K. Rajasekar said:
Hi there,

Can anybody help me in finding out a way to open PPT thru VB programing
for a open pwd/readonly pwd PPTs. The following open statement in my VB
code is not opening the PPT read-only mode automatically. Instead it is
prompting for entering (or selection of readonly) password. I would like to
know how to avoid the 'promptin for pwd panel' to open the ppt in readonly
automatically. Also want to know how to trap the 'open pwd' set ppts
 
Hi Shyam
Thanks for pointing out that there is no way to trap the 'open pwd' even. Is it applicable for open read only also

The requirement is, I need to open a ppt (thru VB
1. If it is having just readonly pwd - then open the ppt in 'Read only' mode automatically. - Can you give the 'Send key code
2. If is is having Open pwd - then trap the even and send a message box
<<doing some operation>
3. In all case (readonly open / normal open) - Close the PPT without saving

For the above requirement, could you get me the equalent VB code
I have seen your nice web site and could not find (probly my poor searching technique) in these lines

Ta
K. Rajasekar
 
Yes, it is applicable for any password protection on the presentation.


You can use this snippet which makes use of SendKeys.
There is no VBA method open a presentation protected with a password in
PowerPoint XP nor is there a way to determine if the presentation is
password protected. However, if you know the password to a presentation,
then you can try the following workaround if it suits you.

1. Open the main presentation and switch to Visual Basic Editor (Alt + F11)
2. Insert a code module into the VBA project.
3. Copy and paste the following snippet.
' ----------snippet -------
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 oPres As Presentation
TimerID = SetTimer(0, 0, 2000, AddressOf PassProc)
' Replace with your password
sPwd = "shyam"
' Replace E:\PresPass.ppt with your path to presentation
Call Presentations.Open("E:\prespass.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
' --------End of Snippet ----
4. Run the macro - OpenPassPres.

You will notice the Password window momentarily and then the password will
be transmitted and the presentation will open.

Regards
Shyam Pillai

http://www.mvps.org/skp

K. Rajasekar said:
Hi Shyam,
Thanks for pointing out that there is no way to trap the 'open pwd' even.
Is it applicable for open read only also?
The requirement is, I need to open a ppt (thru VB)
1. If it is having just readonly pwd - then open the ppt in 'Read only'
mode automatically. - Can you give the 'Send key code'
2. If is is having Open pwd - then trap the even and send a message box.
<<doing some operation>>
3. In all case (readonly open / normal open) - Close the PPT without saving.

For the above requirement, could you get me the equalent VB code?
I have seen your nice web site and could not find (probly my poor
searching technique) in these lines.
 
Hi,

Even this explanation partially helps me to continue my work, the third point still need answer. How to close the ppt with a explicit 'dont save' close.

I got the work around for 'read only pwd' ppt by sendkey(tab and R) and the ppt opens with readonly option. But after processing, while closing (using .close) it says an error message 'object can not modified' - even I opened in readonly mode.
 
Sorry about jumping in, but if you want to save your presentation without
saving (or being asked if you want to save) all you need to do is to tell
PowerPoint it is already saved. This one line of code at the end of your
last macro should do the trick:

ActivePresentation.Saved = True

--
Bill Foley, Microsoft MVP (PowerPoint)
www.pttinc.com
Check out PPT FAQs at: http://www.rdpslides.com/pptfaq/


K. Rajasekar said:
Hi,

Even this explanation partially helps me to continue my work, the third
point still need answer. How to close the ppt with a explicit 'dont save'
close.
I got the work around for 'read only pwd' ppt by sendkey(tab and R) and
the ppt opens with readonly option. But after processing, while closing
(using .close) it says an error message 'object can not modified' - even I
opened in readonly mode.
 
The Close method for the presentation will close the file without prompting
to save the changes.

--
Regards
Shyam Pillai

http://www.mvps.org/skp

K. Rajasekar said:
Hi,

Even this explanation partially helps me to continue my work, the third
point still need answer. How to close the ppt with a explicit 'dont save'
close.
I got the work around for 'read only pwd' ppt by sendkey(tab and R) and
the ppt opens with readonly option. But after processing, while closing
(using .close) it says an error message 'object can not modified' - even I
opened in readonly mode.
 
Hi

Sorry for bothering you a lot.....Still my purpose is not solved. Following my code where I am tring to get the full text from slide master thru VB program. I used SendKeys to open the ppt in 'readonly' mode (if it is having Readonly pwd). After the expected operation while closing the ppt using .Saved=true and .close, it show 'Invalid request.....'. Can anybody help on this
Ta
K. Rajaseka

Dim PptApp As Objec
Dim PptDoc, PptClose As Objec
Dim filecount As Intege
Dim NumShapes, Count As Intege
Dim TotalString As Strin

On Error GoTo FoundErro

Set PptApp = CreateObject("PowerPoint.Application"

If PptApp Is Nothing The
MsgBox "Unable to open MS PowerPoint Application.
Exit Functio
End I

filecount =

DoEvent
Do While filecount < frmPath.List4.ListCoun
frmPath.StatusBar1.Panels.Item(3).Text = "Checking Footer to " & frmPath.List4.List(filecount
DoEvent
SendKeys "{TAB}
SendKeys "R

Set PptDoc = PptApp.Presentations.Open(frmPath.List4.List(filecount), , , msoFalse

If PptDoc Is Nothing The
GoTo NextPleas
Els

'Collecting information from Slide Maste
NumShapes = PptDoc.SlideMaster.Shapes.Coun
Count =
Do While Count <= NumShape
If PptDoc.SlideMaster.Shapes.Item(Count).HasTextFrame = msoTrue The
TotalString = TotalString & PptDoc.SlideMaster.Shapes.Item(Count).TextFrame.TextRange.Tex
End I
Count = Count +
Loo
TotalString = TotalString & PptDoc.SlideMaster.HeadersFooters.Footer.Tex

PptDoc.Saved = True ------------It shows an error of "Invalid request. Presentation can not be saved
PptDoc.Clos
Set PptDoc = Nothin
End I

NextPlease
Err.Clea
TotalString = "
filecount = filecount +
Loo
PptApp.Qui
Set PptApp = Nothin
Exit Functio

FoundError
If Not PptApp Is Nothing The
PptApp.Qui
End I
Set PptApp = Nothin
MsgBox Err.Descriptio

End Functio
 
Is this so difficult to answer?

To simplify the requirement, is there any way of trapping (with error code) - While opening the ppt, if the ppt is having read-only pwd / open pwd then show an error message?
 
Back
Top