The following code is meant to load the current active document path name into the clipboard so that I can paste it using Ctrl + V into a dialog of a SaveAsDaisy addin (which creates an xml translation). This addin is located on a ribbon tab called "Accessibility".

Sometimes it works as intended, but sometimes it fails and Ctrl + V pastes nothing into the dialog, even though the path is now visible in the Clipboard panel.

Sub ClipboardLoadPathName()

        Dim docCurrent          As Document
        Dim strPath             As String
        Dim doPath              As DataObject
        Dim oData               As New DataObject 'object to use the clipboard
        
        Set docCurrent = ActiveDocument
        
        On Error GoTo ErrorHandling
        
        ' --------------------------------------------------------------
        ' Clear the clipboard first to make sure it's empty
        ' --------------------------------------------------------------
        
        oData.SetText Text:=Empty       'Clear
        oData.PutInClipboard            'take in the clipboard to empty it
        
        ' --------------------------------------------------------------
        'Return the path of an open document in the documents collection
        ' --------------------------------------------------------------
        
        strPath = Documents(docCurrent).Path
        Debug.Print strPath
        
        ' ----------------------------------------------------------------
        ' Swap out the SaveAsDaisy Output folder for the XML folder
        ' ----------------------------------------------------------------
        
        strPath = Replace(strPath, "SaveAsDaisy Output", "XML")
        
        Set doPath = New DataObject
        doPath.SetText strPath
        doPath.PutInClipboard
                
        ' ----------------------------------------------------------------
        ' After copying path to clipboard, switch to the Accessibility tab
        ' ----------------------------------------------------------------
        
         docCurrent.Save
                
        SwitchTab "Accessibility" ' calls another function to switch ribbon tab

        Exit Sub
        
ErrorHandling:
    MsgBox "Check that the Accessibility tab is loaded, or save the file somewhere first, and try again."

End Sub
The path name always does appear in the Clipboard panel, but when Ctrl + V fails, it also pastes two rectangles into the document which are hex 3F symbols (or question marks if pasted into the VB window). To proceed, I have to click on the item in the Clipboard panel, and manually copy it again from the document, which defeats the whole purpose of the macro.

Question: is there any obvious reason why this sometimes works and sometimes does not? Is there something weird about Ctrl + V accessing the clipboard contents?

I have noticed different results from Ctrl + V from different methods of clearing the clipboard:

1. The method used by this code will result in Ctrl + V entering those two hex 3F symbols into a document. So the clipboard is not really cleared.

oData.Clear
        oData.SetText Text:=""
        oData.PutInClipboard
2. The method used by this code results in Ctrl + V pasting nothing at all:

Sub ClipboardClear()

    ' using the relevant declarations 

    OpenClipboard (0&)
    EmptyClipboard
    CloseClipboard
    
End Sub