Solved

VBA Word 2000 - Create hyperlink

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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
This video walks the viewer through the process of creating a watermark for their document, customizing it, and saving it for viewing/printing needs.
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

691 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