Coding in support of this post:
http://www.excelfox.com/forum/showth...ll=1#post11018
Code:Sub MSFORMS_Early_Copy_and_Later_Late_Binding_Paste() Rem 1 Late Binding Dim DtaObj As MSForms.DataObject ' RefMSFORMS.JPG : https://imgur.com/8zKpyr2 Set DtaObj = New MSForms.DataObject 'Dim DtaObj As New MSForms.DataObject Rem 1 ' Arbritrary Excel range values copy Let Range("A1").Value = "CellA1": Let Range("A2").Value = "CellA2": Let Range("B1").Value = "CellB1": Let Range("B2").Value = "CellB2" Rem 2 Clipboard Data object stuff - get the long string that is held in some clipboards Range("A1:B2").Copy ' ' This seems to fill Excel, Windows and Office Clipboards http://www.eileenslounge.com/viewtopic.php?f=30&t=31849&p=246889#p246887 ' Get some string version from some clipboard using a DataObject method ' Let Application.CutCopyMode = False ' generally speaking these two code lines will not clear the Windows Clipboards, ' Call ClearOffPainBouton ' but they do for the case of a range copy having put them in. So we can't do these here DtaObj.GetFromClipboard ' ' This is filling a regisrre and possibly sometimes setting referrences that may prevent other things being done, or put them in a Queue, bit most likely to put a spanner in the works Let Application.CutCopyMode = False Call ClearOffPainBouton ' Range("A1:B2").Clear ' ' This will cause us to fail .. very strange .. this could suggest that we are still holding a range referrence at this stage Dim strGet As String: Let strGet = DtaObj.GetText() Range("A1:B2").Clear ' At this point it is fine to do this Rem 3 examine string Call WtchaGot(strIn:=strGet) ' ' Function to see string : https://pastebin.com/gtLaBrf5 '3b Do some modification of the string Let strGet = Replace(strGet, vbTab, "|", 1, -1, vbBinaryCompare) ' replace in the strGet , vbTab , with "|" pipes , I want all output so starting at first character , -1 means replace all occurances , exact match using computer exact digits ' Call ClearWindowsClipboard ' http://www.excelfox.com/forum/showthread.php/2056-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)?p=11020&viewfull=1#post11020 clearing the windows clipboard at this point also messes the simple reverse process from working. This makes no sense at all: Clearly clearing does not always clear things: It may do this in many occasions as one of its actions, but it can also do things which have something near to the opposite effect. Rem 4 Replace the version previously got using another DataObject method '4a) Simple reverse action DtaObj.Clear ' Without this the following 2 line simple reverse action would not work ' DtaObj.SetText Text:=strGet: ' Let strGet = DtaObj.GetText() ' - This always gets the last "addition" ... https://stackoverflow.com/questions/25091571/strange-behavior-from-vba-dataobject-gettext-returns-what-is-currently-on-the-c/54960767#54960767 ' DtaObj.PutInClipboard '4b) Later Late Binding Dim LaterDtaObj As Object Set LaterDtaObj = CreateObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}") 'Set LaterDtaObj = CreateObject("MSForms.DataObject") ' https://bytecomb.com/copy-and-paste-in-vba/ LaterDtaObj.SetText Text:=strGet LaterDtaObj.PutInClipboard Rem 5 ' Excel Range Paste ( using Worksheet.Paste method https://docs.microsoft.com/en-us/office/vba/api/excel.worksheet.paste ) ActiveSheet.Paste Destination:=ActiveSheet.Range("A1") End Sub
Code:' SHimpfGlified Coding Sub Early_Copy_and_Later_Late_Binding_Paste() Rem 1 Late Binding Dim DtaObj As MSForms.DataObject ' RefMSFORMS.JPG : https://imgur.com/8zKpyr2 Set DtaObj = New MSForms.DataObject Rem 1 ' Arbritrary Excel range values copy Let Range("A1").Value = "CellA1": Let Range("A2").Value = "CellA2": Let Range("B1").Value = "CellB1": Let Range("B2").Value = "CellB2" Rem 2 Clipboard Data object stuff - get the long string that is held in some clipboards Range("A1:B2").Copy ' DtaObj.GetFromClipboard ' Dim strGet As String: Let strGet = DtaObj.GetText() Range("A1:B2").Clear Rem 3 examine string ' Call WtchaGot(strIn:=strGet) ' '3b Do some modification of the string Let strGet = Replace(strGet, vbTab, "|", 1, -1, vbBinaryCompare) Rem Simple reverse action. Later Late Binding Dim LaterDtaObj As Object Set LaterDtaObj = CreateObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}") LaterDtaObj.SetText Text:=strGet LaterDtaObj.PutInClipboard Rem 5 ' Excel Range Paste ( using Worksheet.Paste method https://docs.microsoft.com/en-us/office/vba/api/excel.worksheet.paste ) ActiveSheet.Paste Destination:=ActiveSheet.Range("A1") End Sub




Reply With Quote
Bookmarks