Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / June 2007

Tip: Looking for answers? Try searching our database.

Hyperlinks.Add causes Word 2007 to crash

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
sana - 18 Jun 2007 17:52 GMT
Can anyone tell why does Word 2007 crashes when I run this macro?
================================================================

Sub Test1()

Dim wordDoc As Word.Document
Set wordDoc = ActiveDocument

Dim str As String
str = "Hyperlink"
Dim strText As String
strText = "DisplayText"

Dim Hyp As Word.Hyperlinks
Set Hyp = wordDoc.Hyperlinks

Dim sel As Word.Selection
Set sel = Word.Selection

sel.TypeText Text:=" "
Word.ActiveDocument.Hyperlinks.Add Anchor:=sel.Range, Address:= _
       str, SubAddress:="", ScreenTip:="", TextToDisplay:=strText
End Sub

==================================================================

If I remove the optional parameter
  TextToDisplay:=strText
from the statement

Word.ActiveDocument.Hyperlinks.Add Anchor:=sel.Range, Address:= _
       str, SubAddress:="", ScreenTip:="", TextToDisplay:=strText
It works fine!

Thanks in advance,
Peter Jamieson - 19 Jun 2007 08:23 GMT
Don't know but you can avoid the crash by using

Dim strText

or

Dim strText As Variant

instead of

Dim strText As String

Peter Jamieson

> Can anyone tell why does Word 2007 crashes when I run this macro?
> ================================================================
[quoted text clipped - 31 lines]
>
> Thanks in advance,
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.