0

I'm writing some macro for MS Project. I have some URL string and string with text to display. I created hyperlink like:

    wdDoc.Hyperlinks.Add Anchor:=Selection, Address:= _
    urlString, SubAddress:= _
    "", TextToDisplay:= _
    displayText

So, how can I put this link into clipboard?

4
  • msdn.microsoft.com/en-us/library/office/ff192913.aspx Commented Oct 27, 2016 at 6:29
  • I can't figure out how to use it for hyperlinks. Can you help me? Commented Oct 27, 2016 at 13:24
  • In addition, the method description and examples are only for strings. Commented Oct 27, 2016 at 14:19
  • Where do you want to be able to paste the link? Commented Oct 27, 2016 at 15:55

2 Answers 2

0
Sub Tester()

    Dim wdDoc, h, urlString, displayText

    Set wdDoc = ActiveDocument

    urlString = "http://google.com"
    displayText = "google"

    Set h = wdDoc.Hyperlinks.Add(Anchor:=Selection.Range, _
                    Address:=urlString, SubAddress:="", _
                    TextToDisplay:=displayText)

    h.Range.Copy

End Sub
Sign up to request clarification or add additional context in comments.

1 Comment

it's not absolutely correctly works. I tried this macro in the MS Word, there it works, but when I try to use it in the MS Project I began to receive an error "Type mismatch" for the line "Set wdDoc = ActiveDocument" . I added a reference to the MS Word Object Library and this error disappeared, but appeared another error "ActiveX component can't create object 429". How can I fix it?
0

This will work in MS Project with added MS Word Object Library

Dim hLink As Object
Dim wd As Object
Dim appWd As Word.Application
Dim strUrl, strName

Set strUrl = "mysite.com"
Set strName = "My hypelink to mysite.com"

'Create temp Word doc

Set appWd = CreateObject("Word.Application")
Set wdDoc = appWd.Documents.Add

Set hLink = wdDoc.Hyperlinks.Add(Anchor:=wdDoc.Range, _
    Address:=strUrl, _
    SubAddress:="", _
    ScreenTip:="", _
    TextToDisplay:=strName)

'text format
hLink.Range.Font.Name = "Segoe UI"
hLink.Range.Font.Size = 10
hLink.Range.Font.Color = RGB(0, 0, 255)

hLink.Range.Copy

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.