Home Page

 


EARLIER FEATURES

 


FEATURES CONTENTS

 


LATER FEATURES

 

Features Contents


18th December 2005

FILE HYPERLINK MICROSOFT WORD MACRO

Brian Grainger

email.gif (183 bytes)
brian@grainger1.freeserve.co.uk


 

Just recently, at work, we have moved over to Windows XP and Office 2003. Previously we were using Windows NT4 and Office 2000. Because I hate XP I consider this a detrimental step, especially as it has been locked down so much I cannot change things to my liking. However, there have been some improvements and one of them concerns hyperlinks in Word. This triggered me to thinking that a routine I developed for Word 2000 may be useful for others with this older version.

I spend my time working on various space projects and each project consists of a number of tasks - some of which are planned for and some of them are not. I like to keep a record of how each task has been carried out. This is helpful when I have to return to the task after a period of time and try and remember what I had done previously. Most tasks consist of some input triggering it off. Then you decide what needs to be done - which may mean getting some documents to look at, or maybe generating some data. At the end of the day the output of the task is usually in the form of a report or e-mail. I also like to know the steps I took in completing the task, so that I can justify myself if I am asked later.

What I do is keep a 3 column table as a task log. The first column defines inputs. The middle column the process carried out and the final column the output. As a task develops the output of one step may form the input of another. Here is a typical log. It is a bit trivial. In real life things get more complicated and the timescales can last 6 months or more from start to finish.

Input

Process

Output

Informed a design review is coming up on XYZ

Get documents for XYZ

Analysis 1
Analysis 2

Analysis 1

Review and generate comments

Analysis 1 queries

...

   

Response to Analysis 1 queries

Check responses and confirm OK or otherwise.

Close comments 1 &2
Follow up to comment 3

...

   

Most of the inputs and outputs are in the form of reports and e-mails - all of which are kept electronically as files on the computer. What I like to do is to hyperlink these files from my task log so that I can quickly access them. You then have a permanent electronic record of every task, which can be archived and referred to later.

When I was using Word 2000 I found that when one used the Insert - Hyperlink command it was geared to setting a hyperlink to a web page, rather than to a file. You could hyperlink to a file but the number of key presses became tedious. First you had to select Insert - Hyperlink, then click File and then it would only show you Word files so you had to change that to show all files, then you had to select one and then you had to click OK a couple times. I cannot remember all the steps now. I just remember it got tedious after doing it a few times. I decided to write a Word macro instead.

The macro was written to attach a hyperlink to a highlighted phrase, say 'Analysis 1' in the example log above. You would highlight the phrase and then press the keyboard combination to call the macro. A dialog box would appear showing all the files in the same directory as the task log. You select one and click OK. The hyperlink was attached. Simple. Call up macro - click file - click OK!

In order to perform this magic I needed a dialog screen and after a bit of research I decided to use the in-built Word open dialog screen. This worked OK as long as I selected a file from the current directory. If I selected a file from another directory the relative path linking in the hyperlink did not work. This was not a problem as all files related to a particular task and the associated task log were usually stored in the same directory. When they were not, I could always fall back to the standard Insert Hyperlink.

Here is the macro I created.

Sub FileHyperlink()
'
' FileHyperlink Macro
' Macro recorded 20/06/03 by Brian Grainger
'
Dim Fname As String
ChangeFileOpenDirectory ActiveDocument.Path
With Dialogs(wdDialogFileOpen)
    .Display
    Fname = .Name
    If Fname <> "" Then
        ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, _
        Address:=Fname
    End If
End With

End Sub

Microsoft must have realised the Insert Hyperlink function was seriously deficient. In the Word 2003 I now use you see a list of files to choose from as soon as Insert - Hyperlink is selected. I have no need for my macro anymore, but maybe you do!


 

 

 

 


TOP