vba logic?

G

Geoff Cox

Hello,

I am trying to change some code which deleted the action button on the
last slide so that it finds last slides which do not have an action
button ...

code below not working - any ideas as to why please?!

Cheers

Geoff

Dim oSh As Shape

For Each oSh In _
ActivePresentation.Slides(ActivePresentation.Slides.Count) _
.Shapes
If oSh.Type = 1 Then
' 130 = msoShapeActionButtonForwardOrNext
If oSh.AutoShapeType <> 130 Then

MsgBox "no button in last slide of " & strMyFile

End If
End If
Next

End With
 
S

Steve Rindsberg

Hello,

I am trying to change some code which deleted the action button on the
last slide so that it finds last slides which do not have an action
button ...

code below not working - any ideas as to why please?!

It helps to know what "not working" means.


Dim oSh As Shape
Dim bFoundButton as Boolean

bFoundButton = False ' to start

For Each oSh In _
ActivePresentation.Slides(ActivePresentation.Slides.Count) _
.Shapes
If oSh.Type = 1 Then
' 130 = msoShapeActionButtonForwardOrNext
If oSh.AutoShapeType = 130 Then ' we've found the button, set a flag
bFoundButton = True
End If
End If
' Now display a message
If bFoundButton Then
MsgBox "Found a Forward or Next button on the last slide"
else
MsgBox "No Forward/Next buttons here"
End If
Next
 
G

Geoff Cox

It helps to know what "not working" means.

Steve,

Sorry - should have made that more clear. The same thing is happening
with the code below - I am getting multiple "No forward/next buttons"
for a presentation which does not have a forward/next button on the
last slide ... should that happen?

Geoff
 
G

Geoff Cox

It helps to know what "not working" means.

Steve,

What does shape type 1 mean? Can you point at info on the different
values for shape types?

Thanks

Geoff
 
G

Geoff Cox

On Sun, 30 Apr 2006 19:23:22 EDT, Steve Rindsberg

Steve - the code below is finding action buttons OK but is not giving
a message for those presentations where the last slide has no action
button...?

Most of the code is to check each ppt file and then to concentrate on
the last slide etc.

Geoff

Sub ForEachPresentation()
' Run a macro of your choosing on each presentation in a folder

Dim rayFileList() As String
Dim FolderPath As String
Dim FileSpec
Dim strTemp As String
Dim x As Long

' EDIT THESE to suit your situation
FolderPath = "c:\activities\" ' Note: MUST end in \
FileSpec = "*.ppt"
' END OF EDITS

' Fill the array with files that meet the spec above
ReDim rayFileList(1 To 1) As String
strTemp = Dir$(FolderPath & FileSpec)
While strTemp <> ""
rayFileList(UBound(rayFileList)) = FolderPath & strTemp
ReDim Preserve rayFileList(1 To UBound(rayFileList) + 1) As
String
strTemp = Dir
Wend

' array has one blank element at end - don't process it
' don't do anything if there's less than one element
If UBound(rayFileList) > 1 Then
For x = 1 To UBound(rayFileList) - 1
Call MyMacro(rayFileList(x))
Next x
End If

End Sub

Sub MyMacro(strMyFile As String)
' this gets called once for each file that meets the spec you enter in
ForEachPresentation
' strMyFile is set to the file name each time

' Probably at a minimum, you'd want to:
Dim oPresentation As Presentation
Set oPresentation = Presentations.Open(strMyFile)

With oPresentation


Dim oSh As Shape
Dim bFoundButton As Boolean

bFoundButton = False ' to start

For Each oSh In _
ActivePresentation.Slides(ActivePresentation.Slides.Count) _
.Shapes
If oSh.Type = 1 Then
' 130 = msoShapeActionButtonForwardOrNext
If oSh.AutoShapeType = 130 Then ' we've found the button, set
a flag
bFoundButton = True
End If
End If
' Now display a message
If bFoundButton Then
MsgBox "Found a Forward or Next button on the last slide"
Else
MsgBox "No Forward/Next buttons here"
End If
Next


End With

End Sub
 
S

Steve Rindsberg

Dim oSh As Shape
Dim bFoundButton As Boolean

bFoundButton = False ' to start

For Each oSh In _
ActivePresentation.Slides(ActivePresentation.Slides.Count) _
.Shapes
If oSh.Type = 1 Then
' 130 = msoShapeActionButtonForwardOrNext
If oSh.AutoShapeType = 130 Then ' we've found the button, set
a flag
bFoundButton = True
End If
End If
Next

' my mistake ... move this here rather than where it was previously
' in the middle of the loop that checks each shape. Pesky aircode.

' Now display a message
If bFoundButton Then
MsgBox "Found a Forward or Next button on the last slide"
Else
MsgBox "No Forward/Next buttons here"
End If
 
S

Steve Rindsberg

What does shape type 1 mean? Can you point at info on the different
values for shape types?

In the VB editor, press F2 to view the Object Browser
Use the search feature to ferret out the term: msoAutShapeType
That'll give you a list of the different types.

If a shape is a type 1, AutoShape, it can also have an AutoShapeType property
which tells you which of the many types of autoshape it is.

To further stir the pot 'o confusion, the code we're playing with here will
find button autoshapes but will ignore other shapes that happen to have action
settings.

That is, when you add a Next button, you get a specific autoshape type that
just *happens* to have as its default action a Next Slide action setting.

You can change the action setting if you wish, or can assign that action
setting to any other type of shape.

For that reason, if you're really looking for a specific action setting rather
than a button, you might want to test:

If oSh.ActionSettings(ppMouseClick).Action = ppActionNextSlide Then
' etc
' look up ppActionType in the object browser for other Action values
' you may also want to test
' oSh.ActionSettings(ppMouseOver).Action
' for mouseOVER rather than mouseCLICK actions
 
G

Geoff Cox

' my mistake ... move this here rather than where it was previously
' in the middle of the loop that checks each shape. Pesky aircode.

' Now display a message
If bFoundButton Then
MsgBox "Found a Forward or Next button on the last slide"
Else
MsgBox "No Forward/Next buttons here"
End If

Steve,

I am using the code below, as a sub with the code looking at each ppt
file in the folder, which works OK.

When I run the macro it opens all the files - is it possible to run
the code without opening them? Or at least open and then close them?

Cheers

Geoff


Sub MyMacro(strMyFile As String)
' this gets called once for each file that meets the spec you enter in
ForEachPresentation
' strMyFile is set to the file name each time

' Probably at a minimum, you'd want to:
Dim oPresentation As Presentation
Set oPresentation = Presentations.Open(strMyFile)

With oPresentation

Dim oSh As shape
Dim bFoundButton As Boolean

bFoundButton = False ' to start
For Each oSh In _
ActivePresentation.Slides(ActivePresentation.Slides.Count) _
..Shapes
If oSh.Type = 1 Then

If oSh.AutoShapeType = 130 Then
bFoundButton = True
End If
End If
Next

' Now display a message
If bFoundButton Then
MsgBox "Found a Forward or Next button on the last slide"
Else
MsgBox "No Forward/Next buttons here"
End If



End With

End Sub
 
G

Geoff Cox

On Mon, 01 May 2006 11:21:01 EDT, Steve Rindsberg

Steve,

I have made a little progress I think!

Code below finds last slide which either has no shape at all (and
therefore no action button) or has a rectangular shape which is not
an action button. I guess it can be improved?

Just one point - can I stop the ppt files being open after the macro
has run?

Cheers

Geoff



Sub MyMacro(strMyFile As String)

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

With oPresentation

Dim oSh As shape
Dim bFoundButton As Boolean

bFoundButton = False ' to start

With ActivePresentation.Slides(ActivePresentation.Slides.Count)

If .Shapes.Count > 0 Then

For Each oSh In _
ActivePresentation.Slides(ActivePresentation.Slides.Count) _
.Shapes
If oSh.Type = 1 Then
If oSh.AutoShapeType = 130 Then
bFoundButton = True
End If
End If
Next


If Not bFoundButton Then
MsgBox "No button on last slide of " & strMyFile
End If

Else
MsgBox "No shape on this last slide in " & strMyFile
End If

End With
End With

End Sub
 
S

Steve Rindsberg

I am using the code below, as a sub with the code looking at each ppt
file in the folder, which works OK.

When I run the macro it opens all the files - is it possible to run
the code without opening them? Or at least open and then close them?


No to the first, yes to the second.
I've cleaned up the indentation and so on below.
The only real change to the code is the .Close statement toward the end, which
will close the presentation. Also added a bit of clean up at end (setting
varables = Nothing)

Sub MyMacro(strMyFile As String)
'this gets called once for each file that meets the spec you enter in
'ForEachPresentation
'strMyFile is set to the file name each time

Dim oPresentation As Presentation
Dim oSh As Shape
Dim bFoundButton As Boolean

Set oPresentation = Presentations.Open(strMyFile)

With oPresentation

bFoundButton = False ' to start

For Each oSh In _
ActivePresentation.Slides(ActivePresentation.Slides.Count) _
.Shapes
If oSh.Type = 1 Then

If oSh.AutoShapeType = 130 Then
bFoundButton = True
End If
End If
Next ' oSh - shape

'Now display a message
If bFoundButton Then
MsgBox "Found a Forward or Next button on the last slide"
Else
MsgBox "No Forward/Next buttons here"
End If

.Close ' the presentation
End With ' oPresentation
Set oSh = Nothing
Set oPresentation = Nothing

End Sub
 
G

Geoff Cox

No to the first, yes to the second.
I've cleaned up the indentation and so on below.
The only real change to the code is the .Close statement toward the end, which
will close the presentation. Also added a bit of clean up at end (setting
varables = Nothing)

Many thanks Steve!

Cheers

Geoff
 
S

Steve Rindsberg

On Mon, 01 May 2006 11:21:01 EDT, Steve Rindsberg

Steve,

I have made a little progress I think!

Code below finds last slide which either has no shape at all (and
therefore no action button) or has a rectangular shape which is not
an action button. I guess it can be improved?

Just one point - can I stop the ppt files being open after the macro
has run?

Have another look at the last example I posted. There's a line

.Close

just before End With ' presentation
 
G

Geoff Cox

Have another look at the last example I posted. There's a line

.Close

just before End With ' presentation

Yes - have used that Steve - messages passed in the night!

Thanks

Geoff
 

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

Similar Threads


Top