Solved

VBA Word 2000 - Create hyperlink

Posted on 2011-03-16
3
511 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Word 2016 stuck on "starting" splash screen 10 1,974
Converting large .PDF files. 6 65
MS Word Office 365 Mail Merge 2 75
Stop display of alerts in Word via Excel 12 16
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…
Introduction Authors who set out to write any sort of lengthy piece for online submission—be it a long question or comment on a technical form, an article, or a substantial blog entry—often find it useful to work up a draft in an editor other t…
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

808 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