gemmo
gemmo

Reputation: 1456

File path of links in Word Document

I'm working on excel vba, I just want to access a word document, and list the file path of all the links within it. ie. "c:\excelfile.xls"

Upvotes: 0

Views: 680

Answers (2)

L42
L42

Reputation: 19727

If your document is open, try this:

Sub due()
    Dim msWord As Object
    Dim msDoc As Object
    Dim msHlink As Object

    Set msWord = GetObject(, "Word.Application")
    Set msDoc = msWord.Documents(1) 'change to suit

    For Each msHlink In msDoc.Hyperlinks
        Debug.Print msHlink.Address
    Next
End Sub

Word same as Excel have Hyperlinks Collection where you can access all available hyperlinks on the document.

Edit1: To get embedded Excel Object Links you need to access the InlineShapes Collection.
Something like:

Sub due()
    Dim msWord As Word.Application
    Dim msDoc As Word.Document
    Dim iShp As Word.InlineShape

    Set msWord = GetObject(, "Word.Application")
    Set msDoc = msWord.Documents(1) 'change to suit

    For Each iShp In msDoc.InlineShapes
        Debug.Print iShp.LinkFormat.SourceFullName
    Next
End Sub

To get all the available properties for InlineShape object, make sure to add reference to Microsoft Word XX.0 Object Library. Take note that I used Early Binding above. HTH.

Upvotes: 2

Goos van den Bekerom
Goos van den Bekerom

Reputation: 1493

Do you mean this:

Sub OpenWordDocument()

    dim Word as Object
    Set Word = CreateObject("word.Application")

    Word.documents.Open "C:\excelfile.xls"

    Word.Visible = True

End Sub

for the copying you could check out this answer

Upvotes: 0

Related Questions