Control Toolbox text box and vba - a bug?

G

Geoff Cox

Hello,

I wonder if anyone can sort this one?!

I create a presentation with one slide which has a text box inserted
using the Control Toolbox.

The first block of code below is run in order to find the number of
slides in a presentation. It works fine when no text box but with the
text box it does not run and all I can see is that I get an entry in
the Project Explorer

VBA Project(test.ppt)
Microsoft PowerPoint Object
Slide1

(test.ppt is the 1 slide presentation with the text box on it)

Shyam has suggested that this was a bug and said I should try the
second block of code below - but this has the same effect as above.

Any ideas?!

Cheers

Geoff

--------------------------my first code-----------------------------
Sub MyMacro(strMyFile As String)

Dim oPresentation As Presentation
Set oPresentation = Presentations.Open(strMyFile)

With oPresentation
CountSlides = oPresentation.Slides.Count
MsgBox "number of slides in " & strMyFile & " is " _
& CountSlides

End With

oPresentation.Close

End Sub
------------------------------------------------------------

---------------------2nd code--------------------------

Sub check_number_of_slides(strMyFile As String)

Dim secAutomation As MsoAutomationSecurity
Dim oPPT As Presentation
Dim CountSlides As Integer

secAutomation = Application.AutomationSecurity
Application.AutomationSecurity = msoAutomationSecurityForceDisable
Set oPPT = Presentations.Open(FileName:=strMyFile, WithWindow:=False)
Application.AutomationSecurity = secAutomation

CountSlides = oPPT.Slides.Count
MsgBox "number of slides in " & strMyFile & " is " & CountSlides

'oPPT.NewWindow 'Optional if you want to see the document window
oPPT.Close 'Close w/o saving.
Set oPPT = Nothing

End Sub
 
G

Geoff Cox

Hello,

I wonder if anyone can sort this one?!

I create a presentation with one slide which has a text box inserted
using the Control Toolbox.

The first block of code below is run in order to find the number of
slides in a presentation. It works fine when no text box but with the
text box it does not run and all I can see is that I get an entry in
the Project Explorer

A little daylight was brought about by a comment seen in another
context - the macro security settings of PowerPoint apply to the
computer not to a particular presentation.

So, when I open PPT and change the security setting to the low state -
then the vba code works!

However, I would like to know why the following does not work when the
PPT setting is medium - any ideas?

Geoff

Sub check_number_of_slides(strMyFile As String)

Dim secAutomation As MsoAutomationSecurity
Dim oPPT As Presentation
Dim CountSlides As Integer

secAutomation = Application.AutomationSecurity
Application.AutomationSecurity = msoAutomationSecurityLow
Application.AutomationSecurity

Set oPPT = Presentations.Open(FileName:=strMyFile, WithWindow:=False)
CountSlides = oPPT.Slides.Count

oPPT.Close 'Close w/o saving.
Set oPPT = Nothing

End Sub
 

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