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
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