[VBA, MMCpAsLinkDIY] how to send some strings to clipboard? failed many times.

charles c. shared this question 6 days ago
Discussion Open

didn't found in the api manual neither.

could use some help.


ps: almost finished MMCpAsLinkDIY,

only cant copy into the clipboard. otherwise same as in the UI.

Also the gpt4 ALWAYS add application/ActiveDocument before the

Utilities here:

topicOID = Utilities.GuidBase64ToRegistry(topicGUID)
must manually remove them.

Option Explicit

Sub Main()
End Sub

Sub CopyTopicLink()
    Dim selectedTopic As Topic
    Dim topicLink As String
    Dim topicGUID As String
    Dim topicOID As String
    Dim documentPath As String
    Dim documentName As String

    ' Get selected topic
    Set selectedTopic = ActiveDocument.Selection.PrimaryTopic

    ' Get the topic GUID
    topicGUID = selectedTopic.Guid

    ' Convert GUID to OID using ActiveDocument.Utilities.GuidBase64ToRegistry
    topicOID = Utilities.GuidBase64ToRegistry(topicGUID)

    ' Clear the Output tab and print three empty lines
    Call ClearOutputTab
    Debug.Print vbCrLf & vbCrLf & vbCrLf

    ' Print the topic GUID to the Output tab
    Debug.Print "Topic GUID: " & topicGUID

    ' Print the topic OID to the Output tab
    Debug.Print "Topic OID: " & topicOID

    ' Get the document path and name
    documentPath = ActiveDocument.Path
    documentName = ActiveDocument.Name

    ' Encode spaces in the document path and name
    documentPath = Replace(documentPath, " ", "%20")
    documentName = Replace(documentName, " ", "%20")

    ' Generate the topic link
    topicLink = "mj-map:///" & documentPath & "\" & documentName & "#oid=" & topicOID

    ' Copy the topic link to the clipboard
  '  Call Clipboard.SetData(topicLink)

    ' Print the topic link to the Output tab
    Debug.Print "The topic link: " & topicLink

    ' Add hyperlink to the selected topic using the topicGUID
  '  selectedTopic.Hyperlinks.AddHyperlinkToTopicByGuid topicGUID, topicLink

    ' Inform the user that the link has been copied to the clipboard
    MsgBox "The topic link has been copied to the clipboard and added as a hyperlink."
End Sub

Sub ClearOutputTab()
    ' Clear the Output tab by printing a large number of empty lines
    Dim i As Integer
    For i = 1 To 100
        Debug.Print vbCrLf
    Next i
End Sub

Replies (1)


The function "Clipboard Text$" is described in the WWB.com documentation.

Leave a Comment
Attach a file