View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Raul Raul is offline
external usenet poster
 
Posts: 86
Default Use VBA in Excel to Open Word Doc and Create a list of Hyperlinks

I would like to use a routine in Excel to open a Word document from a list
and create a list of the hyperlinks in the document(s).

I can open the word document but I cannot extract the desired hyperlink
information.

Can anyone tell me what is wrong with this code or this methodology?

Sub OpenWordDoc()

Dim WordObj As Object
Dim Fpath As String
Dim LinksList() As Variant
Dim aHyperlink As Hyperlink

Err.Clear
On Error Resume Next

ReDim LinksList(4, 2)

' Set file path
Fpath = "C:\Documents and Settings\UserRoutines\ListHyperlinksTest.doc"

' Open the word document
Set WordObj = CreateObject("Word.Application")
WordObj.Documents.Open (Fpath)
WordObj.Visible = True

' This part works in Word but does not work in Excel
i = 0
For Each aHyperlink In ActiveDocument.Hyperlinks
i = i + 1
LinksList(i, 1) = aHyperlink.TextToDisplay
LinksList(i, 2) = aHyperlink.Address
Next aHyperlink
' End of section that works in Word but does not work in Excel

' Close the file
WordObj.Documents.Close
' Quit Word
WordObj.Quit

End Sub

Thanks in advance,
Raul