VBA - make view active?

G

Geoff Cox

Hello,

The code below works OK except that I would like to show the slide
with this button on it.

I have tried using

If oSh.AutoShapeType = 130 Then
oSh.Select
MsgBox "end button found"

but get error message re "its view must be active". How do I make it
active?


Thanks

Geoff


For Each oSh In oSl.Shapes
If oSh.Type = 1 Then
If oSh.AutoShapeType = 130 Then
MsgBox "end button found"
End If
End If
Next oSh
Next oSl
 
G

Guest

Hi Geoff

I take it the presentation being searched is actually open in edit mode?

Also type 130 (its 132 I think) is not an end show button but as any action
can be assigned to any button or shape this isnt the way to do it
Try

Sub geoff()
Dim osld As Slide
Dim oshp As Shape
For Each osld In ActivePresentation.Slides
For Each oshp In osld.Shapes
If oshp.ActionSettings(ppMouseClick).Action = ppActionEndShow Then
MsgBox ("found it")
osld.Select
'maybe Exit Sub here
End If
Next oshp
Next osld
End Sub
--
I think I would also do an Exit Sub after the selection to jump out of the
loops.

Did that answer the question / help?
_____________________________
John Wilson
Microsoft Certified Office Specialist
http://www.technologytrish.co.uk/ppttipshome.html
 
S

Steve Rindsberg

Hello,

The code below works OK except that I would like to show the slide
with this button on it.

I have tried using

If oSh.AutoShapeType = 130 Then
oSh.Select
MsgBox "end button found"

but get error message re "its view must be active". How do I make it
active?

If you're in slide show view, nothing can be selected, so any attempt in code
to select something will *always* cause an error.

To select a shape, you need to be in edit view.

Maybe something like:

If oSh.AutoShapeType = 130 then
SlideShowWindows(1).View.GoToSlide(oSh.Parent.SlideIndex)
End if
 
G

Geoff Cox

Hi Geoff

I take it the presentation being searched is actually open in edit mode?

Also type 130 (its 132 I think) is not an end show button but as any action
can be assigned to any button or shape this isnt the way to do it
Try

Sub geoff()
Dim osld As Slide
Dim oshp As Shape
For Each osld In ActivePresentation.Slides
For Each oshp In osld.Shapes
If oshp.ActionSettings(ppMouseClick).Action = ppActionEndShow Then
MsgBox ("found it")
osld.Select
'maybe Exit Sub here
End If
Next oshp
Next osld
End Sub

Thanks John - will give this a whirl soon and get back to you.

Cheers

Geoff
 
G

Geoff Cox

If you're in slide show view, nothing can be selected, so any attempt in code
to select something will *always* cause an error.

To select a shape, you need to be in edit view.

Maybe something like:

If oSh.AutoShapeType = 130 then
SlideShowWindows(1).View.GoToSlide(oSh.Parent.SlideIndex)
End if

Thanks Steve - will try this out and get back.

Cheers

Geoff
 
G

Geoff Cox

SlideShowWindows(1).View.GoToSlide(oSh.Parent.SlideIndex)

Steve,

The full code for the sub is below and uses your line above. I get
error message "SlideShowWindows(unknown number): Integer out of range.
1 is not in the valid range 1 to 0"

Any thoughts?

Cheers

Geoff


Sub check_for_button(strMyFile As String)

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

With oPresentation

Dim oSl As Slide

For Each oSl In ActivePresentation.Slides

Dim oSh As shape

For Each oSh In oSl.Shapes
If oSh.Type = 1 Then
If oSh.AutoShapeType = 130 Then
SlideShowWindows(1).View.GotoSlide (oSh.Parent.SlideIndex)
MsgBox "end button found"
End If
End If
Next oSh
Next oSl
oPresentation.Close

End With

Set oSh = Nothing
Set oPresentation = Nothing

End Sub
 
G

Geoff Cox

Can you clarify Geoff. Are you in slide show mode or edit mode?

John,

I am not sure what you mean!

I run the macro from within PowerPoint and the macro works on all the
ppt files in a folder and its sub-folders.

How do I know whether this is slide show or edit mode?

Cheers

Geoff
 
G

Guest

If you open .ppt files then theyre in edit mode (I think!)

slideshowwindows(1) will only work in slideshow mode as there is no
slideshowwindow open in edit mode

Also as I said before to find action buttons or shapes with an action of
"end show" I dont think that you can use type 130 (which is just an action
button) but must use something that detects the actual action e.g
If oshp.ActionSettings(ppMouseClick).Action = ppActionEndShow Then

Did you try my original code?
--

Did that answer the question / help?
_____________________________
John Wilson
Microsoft Certified Office Specialist
http://www.technologytrish.co.uk/ppttipshome.html
 
G

Geoff Cox

Steve and John,

By guess and by God have got code below to work!

The crucial difference is

ActiveWindow.View.GotoSlide (oSl.SlideIndex)

which presumably puts me in edit mode?

Cheers

Geoff



Sub check_for_button(strMyFile As String)

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

With oPresentation

Dim oSl As Slide

For Each oSl In ActivePresentation.Slides

ActiveWindow.View.GotoSlide (oSl.SlideIndex)

Dim oSh As shape

For Each oSh In oSl.Shapes
If oSh.Type = 1 Then
If oSh.AutoShapeType = 130 Then

oSh.Select
MsgBox "end button found in slide " & oSl.SlideIndex
End If
End If
Next oSh
Next oSl
oPresentation.Close

End With

Set oSh = Nothing
Set oPresentation = Nothing

End Sub
 
S

Steve Rindsberg

That was intended to be used only in Slide Show view; that's why I asked.
If you're not in slide show view (which I can see you're not, now that we can
see the full subroutine), it won't work.

Instead, use

ActiveWindow.View.GoToSlide(oSh.Parent.SlideIndex)
 
S

Steve Rindsberg

Steve and John,

By guess and by God have got code below to work!

The crucial difference is

ActiveWindow.View.GotoSlide (oSl.SlideIndex)

which presumably puts me in edit mode?

No, but it works if you ARE in edit mode (aka Normal View or Slide View, as
opposed to SlideShow view)
 
G

Geoff Cox

On Fri, 29 Sep 2006 17:23:35 EDT, Steve Rindsberg


Steve,

Having found the action button which is type 130 the code below will
change its shape to that for 132 but the line

oSh.ActionSettings(ppMouseClick).Action = ppEndShow

only seems to remove the hyperlink rather than change it to End Show.

I am trying to put together your code ideas with John's and falling
down the middle I guess?!

John's code is not working for me yet..

Cheers

Geoff

For Each oSh In oSl.Shapes
If oSh.Type = 1 Then
If oSh.AutoShapeType = 130 Then

oSh.AutoShapeType = 132
oSh.ActionSettings(ppMouseClick).Action = ppEndShow

'oSh.Select
'MsgBox "end button found in slide " & oSl.SlideIndex
End If
End If
Next oSh
Next oSl
 
G

Geoff Cox

If you open .ppt files then theyre in edit mode (I think!)

slideshowwindows(1) will only work in slideshow mode as there is no
slideshowwindow open in edit mode

Also as I said before to find action buttons or shapes with an action of
"end show" I dont think that you can use type 130 (which is just an action
button) but must use something that detects the actual action e.g
If oshp.ActionSettings(ppMouseClick).Action = ppActionEndShow Then

Did you try my original code?

John,

I now see the difference bewteen the shape of the button and its
action. I would like to change any ForwardOrNext buttons to EndShow
buttons.

My code based on yours is giving me multiple "found it"s on slides
where there are no buttons so I must have made a mistake in the code -
can you see where?

Cheers

Geoff

Sub check_for_button(strMyFile As String)

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

With oPresentation

Dim osld As Slide
Dim oshp As shape
For Each osld In ActivePresentation.Slides
For Each oshp In osld.Shapes
If oshp.ActionSettings(ppMouseClick).Action = _
ppForwardOrNext Then
MsgBox ("found it") & " slide " & osld.SlideIndex
osld.Select

'maybe Exit Sub here

End If
Next oshp
Next osld

oPresentation.Save
oPresentation.Close

End With

Set oshp = Nothing
Set osld = Nothing
Set oPresentation = Nothing

End Sub
 
S

Steve Rindsberg

On Fri, 29 Sep 2006 17:23:35 EDT, Steve Rindsberg

Steve,

Having found the action button which is type 130 the code below will
change its shape to that for 132 but the line

oSh.ActionSettings(ppMouseClick).Action = ppEndShow

only seems to remove the hyperlink rather than change it to End Show.

I am trying to put together your code ideas with John's and falling
down the middle I guess?!

John's code is not working for me yet..

Cheers

Geoff

For Each oSh In oSl.Shapes
If oSh.Type = 1 Then
If oSh.AutoShapeType = 130 Then

oSh.AutoShapeType = 132
oSh.ActionSettings(ppMouseClick).Action = ppEndShow

That should be ppActionEndShow
With that change it works here
 
G

Geoff Cox

That should be ppActionEndShow
With that change it works here

Streve,

Thanks for above. Odd thing is that if I run the code simply to find
and select the type 130 button, all the buttons are found.

When I remove the message line and the select but add the

oSh.AutoShapeType = 132
oSh.ActionSettings(ppMouseClick).Action = ppActionEndShow

all of the shapes are changed to the 132 type but not all of the
hyperlinks are changed to End Show.

Any ideas please? Full code below.

Geoff

Sub search_for_button_steve()

Set fs = Application.FileSearch
With fs
.LookIn = "C:\test\activities\"
.SearchSubFolders = True
.FileName = "*.ppt"
If .Execute() > 0 Then

For i = 1 To .FoundFiles.Count

check_for_button (.FoundFiles(i))

Next i
Else
MsgBox "There were no files found."
End If
End With

End Sub

Sub check_for_button(strMyFile As String)

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

With oPresentation

Dim oSl As Slide

For Each oSl In ActivePresentation.Slides

ActiveWindow.View.GotoSlide (oSl.SlideIndex)

Dim oSh As shape

For Each oSh In oSl.Shapes
If oSh.Type = 1 Then
If oSh.AutoShapeType = 130 Then

oSh.AutoShapeType = 132
oSh.ActionSettings(ppMouseClick).Action = ppActionEndShow

'oSh.Select
'MsgBox "end button found in slide " & oSl.SlideIndex
End If
End If
Next oSh
Next oSl
oPresentation.Save
oPresentation.Close

End With

Set oSh = Nothing
Set oPresentation = Nothing

End Sub
 
S

Steve Rindsberg

Streve,

Thanks for above. Odd thing is that if I run the code simply to find
and select the type 130 button, all the buttons are found.

When I remove the message line and the select but add the

oSh.AutoShapeType = 132
oSh.ActionSettings(ppMouseClick).Action = ppActionEndShow

all of the shapes are changed to the 132 type but not all of the
hyperlinks are changed to End Show.

Not sure why that should be, unless some of the shapes are non-Autoshapes.
Have a look below for one other correction, and by the way, kudos on your
persistence, sir. This is not easy stuff to wrap your head around when getting
started.
Any ideas please? Full code below.

Geoff

Sub search_for_button_steve()

Set fs = Application.FileSearch
With fs
.LookIn = "C:\test\activities\"
.SearchSubFolders = True
.FileName = "*.ppt"
If .Execute() > 0 Then

For i = 1 To .FoundFiles.Count

check_for_button (.FoundFiles(i))

Next i
Else
MsgBox "There were no files found."
End If
End With

End Sub

Sub check_for_button(strMyFile As String)

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

With oPresentation

Dim oSl As Slide

For Each oSl In ActivePresentation.Slides

ActivePresentation may not always be the one you just opened (oPresentation)
Make that

For Each oSl in oPresentation
ActiveWindow.View.GotoSlide (oSl.SlideIndex)

Nothing *wrong* with going to the slide, but it's not necessary, and it will
slow things down. On the other hand, it's a useful progress indicator.
 
G

Geoff Cox

Not sure why that should be, unless some of the shapes are non-Autoshapes.

Steve,

the code wouldn't find and select the buttons if they were not
Autoshapes, would it?
ActivePresentation may not always be the one you just opened (oPresentation)
Make that

For Each oSl in oPresentation

When I try this I get error message "Object doesn't support this
property or method" ?!

Cheers

Geoff
 
S

Steve Rindsberg

[snippage applied]

I see you got my last little fumble worked out. Between John's tapdancing
fingers and my happythumbs it's a wonder you haven't run screaming into the
hills.

Thanks for sending the files, and thansk especially for simplifying it to just
the bits needed to "state the case" so to speak.

It seems that an applied hyperlink trumps action settings.

In your file #2, the action button has a hyperlink applied and you've probably
noticed that it stays put after you run the macro.

I modified it to add:

oSh.ActionSettings(ppMouseClick).Hyperlink.Delete

just before this:

osh.ActionSettings(ppMouseClick).Action = ppActionEndShow

and it works here.
 

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

finding oHl.Address for an action button? 2
VBA question 11
code not working - why? 10
VBA error? 2
vba logic? 13
VBA removes other animation?! 6
how get the Hammer sound? 1
Help with VBA 4

Top