Creating Hyperlinks in word

  HIT any key 10:03 04 May 2007

I have a (long) word document that is a table listing PDF files. In column is is the document reference and column 2 is the document description.

I want to make the document reference in column 1 a hyperlink to the document.

I can do this manually by :-
a) Highlight the document reference
b) Right click and select hyperlink
c) type in the document reference in the address
d) Click OK

This is fine but, with hundreds of documents to reference, it is very long winded. This is made worse by the fact that you cannot paste into the address box of the hyperlink definition box.

Is there any simpler way of doing this? I guess a macro but, as I have never written one, I am not sure where to start.

  VoG II 10:13 04 May 2007

Have you tried recording a macro? - the code (ALT+F11 to view it) should give you a hint.

  HIT any key 10:15 04 May 2007

No - I have not tried that (because I don't know how). I will experiment and see if I can work it out.

  VoG II 10:17 04 May 2007

Tools > Macro > Record New Macro.

Then carry out the steps to add a hyperlink, stop the recorder and examine the code.

  HIT any key 10:17 04 May 2007

OK - I tried 'Start Recording a macro' but it would not then let me highlight anything with the cursor.

  VoG II 10:18 04 May 2007

Ah - you need to use the arrow keys to navigate within the document.

This would actually be much easier in Excel.

  HIT any key 10:25 04 May 2007

OK - I had just worked out that I could manage without the cursor but then the macro would record what I typed in rather than the field contents.

I could equally well do it in Excel as it is just a clickable index. How would I do it there?

  HIT any key 10:29 04 May 2007

OK - I have imported it into EXCEL and it has retained the hyperlinks that I had already done but I cant see an easier way to do this myself.

  VoG II 10:40 04 May 2007

Assuming that the data is in columns A and B starting at Row 2:

ALT + F11 to open the Visual Basic Editor. Insert > Module. Copy and paste in the following code:

Sub HyperlinkConverter()
Dim lastrow As Long, i As Long, pdf As String
Application.ScreenUpdating = False
Application.Calculation = xlManual
lastrow = Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lastrow
pdf = Cells(i, 1).Value
ActiveSheet.Hyperlinks.Add Anchor:=Cells(i, 1), Address:=pdf, TextToDisplay:=pdf
Next i
Application.ScreenUpdating = True
Application.Calculation = xlAutomatic
End Sub

Close the VBE. Select the sheet containing the data, Tools > Macro > Macros, highlight HyperlinkConverter and click the Run button.

  HIT any key 12:43 04 May 2007

That worked very well - thank you very much.

This thread is now locked and can not be replied to.

Elsewhere on IDG sites

Galaxy Note 8 vs iPhone X

Awful clip art from 1994 is being tweeted every hour by a bot

iPhone X vs Samsung Galaxy Note 8

Les meilleurs navigateurs internet 2017