Solved

VBA Word 2000 - Create hyperlink

Posted on 2011-03-16
3
510 Views
Last Modified: 2012-05-11
Dear Experts,

I do not have any experience applying VBA in Word, could you please advise how to do with VBA converting texts to hyperlink?

Basically I have a file on path D:\ASN\Test.xls, for this I would like to create hyperlink like it is done manually in the attached Word file.

My final target anyway to assign this file name to a variable like FileName = "D:\ASN\Test.xls", and based on that create hyperlink.

In my daily work have several such paths which needs to be sent for people in mail, so would like if the word could generate them.

thanks,
CreateHyperlink.doc
0
Comment
Question by:csehz
  • 2
3 Comments
 
LVL 1

Author Comment

by:csehz
ID: 35154914
In the meantime I have working macro in Excel for such target in the attached Code,

Do you think that is it possible to do this in Word? The only difference would be just that the hyperlink should be for example in the next row instead of cell A1


Sub CreateHyperlinks2()
Dim FileLink As String
    
FileLink = "D:\ASN\Test.xls"

Worksheets("Sheet1").Range("A1").Formula = "=HYPERLINK(""" & FileLink & """,""" & FileLink & """)"
Worksheets("Sheet1").Range("A1").Font.Color = 16711680

End Sub

Open in new window

0
 
LVL 4

Accepted Solution

by:
jmdion earned 500 total points
ID: 35155948
See if this works.


Sub CreateHyperlink()

    Dim FileName As String
    FileName = "D:\ASN\Test.xls"
    
    Dim rng As Range
    Set rng = Selection.Range
    rng.InsertAfter vbCrLf
    rng.Collapse wdCollapseEnd

    ActiveDocument.Hyperlinks.Add Anchor:=rng, Address:=FileName
    
End Sub

Open in new window

0
 
LVL 1

Author Closing Comment

by:csehz
ID: 35156003
That is perfect :-) Thanks
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you ever need to create a 20 page Word document for some testing purpose? Are you tired of copying & pasting old boring "lorem ipsum" text over and over again, increasing font size and line space in order to make the document 20+ pages long? Look…
Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question