?
Solved

VBA Word 2000 - Create hyperlink

Posted on 2011-03-16
3
Medium Priority
?
517 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

I'm writing to share my clumsy experience in using this elegant tool so you can avoid every stupid mistake I made. (I leave it to the authorities to decide if this deserves a place in the Knowledge archives.)  Now that I am on the other side of my l…
I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.
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:

762 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