breaklinks

T

timeless

I would like to use this code to break links in my ppt presentations,
but it seems it works only in debug mode: (step by step)

Sub BreakLinks()
Dim oSld As Slide
Dim oShp As Shape
Dim oCmdButton As CommandBarButton
Set oCmdButton = CommandBars("Standard").Controls.Add(ID:=2956)
ActiveWindow.ViewType = ppViewSlide
For Each oSld In ActivePresentation.Slides
For Each oShp In oSld.Shapes
If oShp.Type = msoLinkedOLEObject Then
ActiveWindow.View.GotoSlide oSld.SlideIndex
oShp.Select
Application.CommandBars.FindControl(ID:=2956).Execute
' Do not forget to add this line else you will get erratic
' results since the code execution does not halt while menu
' command is executed hence we have to let the execution
' complete before proceeding.
DoEvents
End If
Next oShp
Next oSld
oCmdButton.Delete
End Sub

any idea ?
 
T

timeless

Steve Rindsberg said:
You may need to add a few more DoEvents statements, and add a couple
after adding the command bar control.




==============================
PPT Frequently Asked Questions
http://www.pptfaq.com/

PPTools add-ins for PowerPoint
http://www.pptools.com/

I am not an expert of VB.
Can you tell me more exactly what i have to add
or a more simple way (if there is).
 
T

timeless

Steve Rindsberg said:
Doevents
Doevents
Doevents
' in some odd instances I've needed to add as many as five of these!


' and a few more here:
Doevents
Doevents
Doevents



See new lines inserted above.
==============================

I have inserted a lot of lines in the places as you did, and now
the macro deletes some links, but not all the links.
It works well, instead, if i run it in debug mode, step by step.
What was wrong.
 
T

timeless

Steve Rindsberg said:
One other thing to try:

Instead of this part:


Do this:

Dim x as long

For x = oSld.Shapes.Count to 1 Step -1
Set oShp = oSld.Shapes(x)

If oShp.Type = msoLinkedOLEObject Then
ActiveWindow.View.GotoSlide oSld.SlideIndex
oShp.Select
Application.CommandBars.FindControl(ID:=2956).Execute
' Do not forget to add this line else you will get erratic
' results since the code execution does not halt while menu
' command is executed hence we have to let the execution
' complete before proceeding.

DoEvents
' and a few more here:
Doevents
Doevents
Doevents

End If
Next oShp

Done but it gives a compilation error, it says something like
Next oShp is not allowed (may be becouse the loop begins with for x).
Can you rewrite the entire code
 
T

timeless

"Steve Rindsberg" <[email protected]> has written:
Post back with what you arrive at.

I have made some adjustments and this is what i have got.
This code works better that before, It deletes almost all
links but not all the links.
Then i have introduced a loop that let the macro run several times
and after that it looks like all links were finally deleted for now
(don't know in the future).


Sub BreakLinks()

For z = 1 To 10

'****************************************************

Dim oSld As Slide
Dim oShp As Shape
Dim oCmdButton As CommandBarButton
Set oCmdButton = CommandBars("Standard").Controls.Add(Id:=2956)

DoEvents
DoEvents
DoEvents
DoEvents
' in some odd instances I've needed to add as many as five of these!

ActiveWindow.ViewType = ppViewSlide

Dim x As Long

For Each oSld In ActivePresentation.Slides
For x = oSld.Shapes.Count To 1 Step -1
Set oShp = oSld.Shapes(x)

If oShp.Type = msoLinkedOLEObject Then
ActiveWindow.View.GotoSlide oSld.SlideIndex
oShp.Select
Application.CommandBars.FindControl(Id:=2956).Execute
' Do not forget to add this line else you will get erratic
' results since the code execution does not halt while menu
' command is executed hence we have to let the execution
' complete before proceeding.

' and a few more here:
DoEvents
DoEvents
DoEvents
DoEvents

End If
'Next oShp
Next

Next oSld
oCmdButton.Delete

'****************************************************

Next z

End Sub


Do you think could be something to do to let it work better.
 

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