放入剪贴板一些超链接(VBA)

时间:2016-10-27 06:21:49

标签: vba hyperlink clipboard ms-project

我正在为MS Project编写一些宏。我有一些URL字符串和字符串,显示文本。 我创建了像:

这样的超链接
    wdDoc.Hyperlinks.Add Anchor:=Selection, Address:= _
    urlString, SubAddress:= _
    "", TextToDisplay:= _
    displayText

那么,如何将此链接放入剪贴板?

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

这将在MS Project中使用添加的MS Word对象库

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