Creating a hyperlinked document based on folder contects

S

Steve L

I would like to know if it is possible to have a document read a folders
contents and create hyperlinks to the files in that folder based on the file
name.

Thanks,
Steve
 
S

Steve Yandl

You can try this subroutine. Just change "C:\Test" to the actual target
folder where you want to hyperlink to files. I have it set up to use the
file name as the text show which is what I think you wanted from your
question and I set it up so each link is a new paragraph.

_________________________________

Sub HyperToFldrFiles()

Dim strTgtFldr As String
Dim strShow As String

' Designate the folder where files are found
strTgtFldr = "C:\Test"

Set fso = CreateObject("Scripting.FileSystemObject")
Set fldTarget = fso.GetFolder(strTgtFldr)

Selection.TypeParagraph

For Each myFile In fldTarget.Files
strShow = fso.GetFileName(myFile)
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, _
Address:=myFile, TextToDisplay:=strShow
Selection.TypeParagraph
Next myFile

End Sub
__________________________________


Steve Yandl
 
S

Steve L

Thanks! That worked great.

Steve

Steve Yandl said:
You can try this subroutine. Just change "C:\Test" to the actual target
folder where you want to hyperlink to files. I have it set up to use the
file name as the text show which is what I think you wanted from your
question and I set it up so each link is a new paragraph.

_________________________________

Sub HyperToFldrFiles()

Dim strTgtFldr As String
Dim strShow As String

' Designate the folder where files are found
strTgtFldr = "C:\Test"

Set fso = CreateObject("Scripting.FileSystemObject")
Set fldTarget = fso.GetFolder(strTgtFldr)

Selection.TypeParagraph

For Each myFile In fldTarget.Files
strShow = fso.GetFileName(myFile)
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, _
Address:=myFile, TextToDisplay:=strShow
Selection.TypeParagraph
Next myFile

End Sub
__________________________________


Steve Yandl
 

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