PowerPoint 2007 crashes using hyperlinks from VBA

  • Thread starter Thread starter DanP
  • Start date Start date
D

DanP

I can cause PowerPoint 2007 to crash fairly repeatably when trying to create
or clear hyperlinks from VBA (not manually from the GUI). Has anyone else
seen this problem? Is there somewhere I can send my test case?

Dan Proskauer
 
Sure. Here is the code I am working with.

' This code goes with a simple PowerPoint presentation:
' Slide 1: bullets
' Slide 2: title with a table containing at least one cell with text in it
' (mine is 2 rows by 5 columns with text in cell 1 only)
' Slide 3: title and bullets with one bullet containing the text "Slide 2" and
' one containint "Slide 4"
' Slide 4: anything
'
' Note that you may have to determine the actual slide IDs of your slides
and change the code
' to match them (first argument in the SubAddress property of the
Hyperlink object).
'

' I have seen PowerPoint 2007 crash multiple times while working on this
simple code
' trying to restore basic hyperlink functionality from VBA that I had in
Office 2003.

' This code goes with slide 2
Sub SeeSubAddressProblem()
' This works

ActivePresentation.Slides(2).Shapes(1).TextFrame.TextRange.ActionSettings(ppMouseClick).Hyperlink.Address = ""

ActivePresentation.Slides(2).Shapes(1).TextFrame.TextRange.ActionSettings(ppMouseClick).Hyperlink.SubAddress = "259,4,Slide 4"

' This doesn't!
ActivePresentation.Slides(2).Shapes(2).Table.Cell(1,
1).Shape.TextFrame.TextRange.ActionSettings(ppMouseClick).Hyperlink.Address =
""
ActivePresentation.Slides(2).Shapes(2).Table.Cell(1,
1).Shape.TextFrame.TextRange.ActionSettings(ppMouseClick).Hyperlink.SubAddress = "259,4,Slide 4"
End Sub

' This code goes with Slide 3
Sub SeeCharacterSubsetProblem()
' This works in Office 2003, and seems to sometimes work in Office 2007
Dim i As Integer

' Find the text "Slide 2" and make it a hyperlink to slide 2
i = InStr(1, ActivePresentation.Slides(3).Shapes(2).TextFrame.TextRange,
"Slide 2")
With
ActivePresentation.Slides(3).Shapes(2).TextFrame.TextRange.Characters(i,
Len("Slide 2")).ActionSettings(ppMouseClick).Hyperlink
.Address = ""
.SubAddress = "252,2,Slide 2"
End With

' Find the text "Slide 4" and make it a hyperlink to slide 4
i = InStr(1, ActivePresentation.Slides(3).Shapes(2).TextFrame.TextRange,
"Slide 4")
With
ActivePresentation.Slides(3).Shapes(2).TextFrame.TextRange.Characters(i,
Len("Slide 4")).ActionSettings(ppMouseClick).Hyperlink
.Address = ""
.SubAddress = "259,4,Slide 4"
End With
End Sub


' This code simply tries to remove any hyperlinks from the presentation.
' Run-time errors are encountered (that shouldn't be there) executing the
' Delete method on existing hyperlinks. Also after executing this code and
' while stopped at a trap, PowerPoint may crash (you get the "Do you want to
send an error report"
' dialog box).
Private Sub ClearAllHyperlinks()
Dim sl As Slide
Dim sh As Shape
Dim r As Integer
Dim c As Integer

For Each sl In ActivePresentation.Slides
For Each sh In sl.Shapes
'On Error Resume Next
If sh.HasTable Then
For r = 1 To sh.Table.Rows.Count
For c = 1 To sh.Table.Columns.Count
If Not sh.Table.Cell(r,
c).Shape.TextFrame.TextRange.ActionSettings(ppMouseClick).Hyperlink Is
Nothing Then
sh.Table.Cell(r,
c).Shape.TextFrame.TextRange.ActionSettings(ppMouseClick).Hyperlink.Delete
End If
Next c
Next r
End If
If sh.HasTextFrame Then
If Not
sh.TextFrame.TextRange.ActionSettings(ppMouseClick).Hyperlink Is Nothing Then

sh.TextFrame.TextRange.ActionSettings(ppMouseClick).Hyperlink.Delete
End If
End If
Next sh
Next sl

End Sub
 
For example, using the code I just posted I did the following:

1. Start PowerPoint
2. Alt-F11 to go to VBA
3. Ctrl-A to copy all text
4. Pasted code into discussion group
5. Put cursor in SeeSubAddressProblem() and pressed F-5
6. Got run-time error on this line:

ActivePresentation.Slides(2).Shapes(2).Table.Cell(1,
1).Shape.TextFrame.TextRange.ActionSettings(ppMouseClick).Hyperlink.Address =
""

7. Selected text below and added to watch window

ActivePresentation.Slides(2).Shapes(2).Table.Cell(1,
1).Shape.TextFrame.TextRange.ActionSettings(ppMouseClick).Hyperlink

8. Expanded hyperlink object in watch window (my presentation had one there
already)
9. Moved cursor to line above and pressed ctrl-v (meaning to paste in the
text from the variable I just added to the watch window, but the paste buffer
still had all the code in it - oops!)
10. Said, "OK" to this will reset your project
11. PowerPoint crashed
12. After sending error report Office pointed out that I am experiencing a
lot of crashes (correct) and suggested running diagnositcs. Ran them. No
problems found.
 
I'll eagerly await SP1 and hope for the best. Is there any way to get this
test case to the team working on SP1 so they can use it as part of their
testing?

Thanks.

Dan
 
I'll eagerly await SP1 and hope for the best. Is there any way to get this
test case to the team working on SP1 so they can use it as part of their
testing?

If you can package it up as a single PPT that demonstrates the problem as
simply/directly as possible, I'll be happy to send it along to the right folks.

Email to steve at-sign pptools dot com
 
Thanks. File sent.

- Dan

Steve Rindsberg said:
If you can package it up as a single PPT that demonstrates the problem as
simply/directly as possible, I'll be happy to send it along to the right folks.

Email to steve at-sign pptools dot com


-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
 
Back
Top