Jump to content

Creating Multiple Hyperlinks


seekaye

Recommended Posts

I have a directory with 50 or so word/excel files in

i'd like to create a hyperlink for each one in word

e.g. if the first file was MyFile.doc

the first line on my word doc would be MyFile.doc (or even better jusy MyFile

Is this possible? it takes ages to do each one indiviudally

can anyone write me a macro?

thanks

Link to comment
Share on other sites


I'm sure there's a magic macro out there, but being a web dev, I'd try this (it might not even work as I'm sure Word links are very different than HTML links but it's worth a shot).

Find some classic ASP code (I have some but not on me) that looks at the folder and generates HTML links. Since classic ASP is usually VBScript, you can easily modify it to run in DOS and pipe it out to a .HTML file. View the file in your web browser, then copy and paste the text

Link to comment
Share on other sites

in firefox type in the path to the folder you want the list made from.

It will list all of the folders and directories in a hyperlink.

Copy and paste the page into word.

You need to reformat it to your desired look and to remove date and time stamps.

Link to comment
Share on other sites

many thanks for your suggestions

i moved away from macros and into VB express and came up with this solution (eventually..)

i'd never interacted with word from VB express before i tried this.

[microsoft word 11.0 object library needs added to COM references]

'CODE START

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'USER SELECTS A FILE AND STORES IT IN FILE

Dim file As String

file = ""

OpenFileDialog1.FileName = ""

If OpenFileDialog1.ShowDialog() <> Windows.Forms.DialogResult.Cancel Then

file = OpenFileDialog1.FileName

End If

'STORE ALL THE FILES IN THE SAME DIRECTORY IN A NEW ARRAY CALLED FILE

Dim files() As String = System.IO.Directory.GetFiles(GetDir(file), _

"*.*", IO.SearchOption.TopDirectoryOnly)

Dim a As Integer

'OPENS UP A NEW WORD DOCUMENT

Dim objWord As New word.application

objWord.Visible = True

objWord.Documents.Add()

'FOR EVERY FILE IN THE files ARRAY CREATES A HYPERLINK IN THE WORD DOC

For a = 0 To UBound(files)

objWord.Selection.Hyperlinks.Add(Anchor:=objWord.Selection.Range, _

Address:=files(a), _

SubAddress:="", _

ScreenTip:="", TextToDisplay:=GetFile(files(a)) + Chr(13))

Next

End Sub

'RETURNS THE PATH OF THE DIRECTORY OF A GIVEN FILE

Function GetDir(ByVal file)

GetDir = ""

Dim a, last As Integer

For a = 1 To Len(file)

If Mid(file, a, 1) = "\" Then last = a

Next

For a = 1 To last - 1

GetDir = GetDir + Mid(file, a, 1)

Next

MsgBox(GetDir)

End Function

'RETURNS THE FILE NAME GIVEN THE ENTIRE PATH

Function GetFile(ByVal file)

GetFile = ""

Dim a As Integer

For a = 1 To Len(file)

If Mid(file, a, 1) = "\" Then

GetFile = ""

Else

GetFile = GetFile + Mid(file, a, 1)

End If

Next

End Function

End Class

'CODE ENDS

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...