There is a work around what solves the Excel to Excel copy problem but now I have a problem when pasting it in any other application
Based on the following posts I adapted the code mentioned there for VBA. The problem is now, that Windows now pastes the plain text in other application but it works flawless in Excel.
I added some GIFs at the end of this post for clarification.
stackoverflow - Excel VBA code to copy a specific string to clipboard
Byte Comb Copy and Paste in VBA
stackoverflow - How do I copy formatted HTML string into a Clipboard for paste using C#?
Mike Stall's .NET Debugging Blog - Copying HTML on the clipboard
The links above lead to the subroutine what puts the formated HTML link in the clipboard:
Public Sub CopyCellHyperlinkToClipboard(sLink As String, sDescription As String)
Dim objData As Object
On Error Resume Next
' this is a late bound MSForms.DataObject
Set objData = CreateObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
' copy current cell formula to clipboard
With objData
.SetText CreateHTMLString(sLink, sDescription)
.PutInClipboard
End With
End Sub
stackoverflow - How to set HTML to clipboard in C#?
Mike Stall's .NET Debugging Blog - Copying HTML on the clipboard
The links above lead to the function what creates the actual HTML string:
Function CreateHTMLString(sLink As String, sDescription As String)
Dim sContextStart As String, sContextEnd As String, m_sDescription As String, sHtmlFragment As String, sData As String, sSourceURL As String
m_sDescription = "Version:1.0" + Constants.vbCrLf _
+ "StartHTML:aaaaaaaaaa" + Constants.vbCrLf _
+ "EndHTML:bbbbbbbbbb" + Constants.vbCrLf _
+ "StartFragment:cccccccccc" + Constants.vbCrLf _
+ "EndFragment:dddddddddd" + Constants.vbCrLf
sContextStart = "<HTML><BODY><!--StartFragment -->"
'sSourceURL = "" + Constants.vbCrLf
sHtmlFragment = "<A HREF=" + Strings.Chr(34) + sLink + Strings.Chr(34) + ">" + sDescription + "</A>"
sContextEnd = "<!--EndFragment --></BODY></HTML>"
sData = m_sDescription + sContextStart + sHtmlFragment + sContextEnd
sData = Replace(sData, "aaaaaaaaaa", PadLeft(10, "0", Len(m_sDescription)))
sData = Replace(sData, "bbbbbbbbbb", PadLeft(10, "0", Len(sData)))
sData = Replace(sData, "cccccccccc", PadLeft(10, "0", Len(m_sDescription + sContextStart)))
sData = Replace(sData, "dddddddddd", PadLeft(10, "0", Len(m_sDescription + sContextStart + sHtmlFragment)))
'sData.Dump();
CreateHTMLString = sData
End Function
Since padding isn't supported by VBA I created this function based on the the link below:
stackoverflow - Any method equivalent to PadLeft/PadRight?
Function PadLeft(iLength As Integer, cChar As String, sText As String)
cChar = Left(cChar, 1)
PadLeft = Right(String(iLength, cChar) & sText, iLength)
End Function
Insert a hyperlink from instance of Excel 2010 to another one, as you can see it insert only the label of the hyperlink:
Insert a hyperlink in Excel in another application works flawless:
Therefore I wrote the code above. Now Excel2Excel works:
but it doesn't work for other applications:
