It isn't clear whether you need help with the clipboard piece of the
pie or the text parsing piece. The code below does both. You'll need a
reference to the Forms library, where the DataObject is defined. In
VBA, go to the Tools menu and choose References. There, scroll down to
Microsoft Forms 2.0 Object Library and check that entry. Then use code
like the following:
Sub AAA()
Dim DataObj As MSForms.DataObject
Dim S As String
Dim T As String
Dim N As Long
Dim M As Long
Dim LineContent() As String
Dim Start1 As Double
Dim End1 As Double
Dim Start2 As Double
Dim End2 As Double
Dim Lines() As String
Set DataObj = New MSForms.DataObject
'>>> BEGIN TEST
' This is just a test to put something in the clipboard.
' Omit from final code.
T = "Start: (') (915855.639280, 638485.145786)" & vbCrLf & _
"End: (') (917162.295718, 637714.747829)"
DataObj.SetText T
DataObj.PutInClipboard
'<<< END TEST
''''''''''''''''''''''''''''''''''''''''''
' Get text from clipboard into variable S.
DataObj.GetFromClipboard
S = DataObj.GetText
' If all you need help on is the clipboard piece,
' the code ends here. The clipboard content is in
' the variable S.
''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''
' PARSING THE CONTENT OF THE DATA
''''''''''''''''''''''''''''''''''''''''''
' first single space everything
N = InStr(1, S, Space(2), vbBinaryCompare)
Do Until N = 0
S = Replace(S, Space(2), Space(1))
N = InStr(1, S, Space(2), vbBinaryCompare)
Loop
' break apart into lines
Lines = Split(S, vbCrLf)
' N = position of second open paren
N = InStr(InStr(1, Lines(0), "(", vbBinaryCompare) + 1, Lines(0), "(")
' get text within parentheses
S = Mid(Lines(0), N + 1, Len(Lines(0)) - N - 1)
LineContent = Split(S, ",")
' Start1 and Start2 are the values in the first line
' of text from the clipboard.
Start1 = CDbl(LineContent(0))
Start2 = CDbl(LineContent(1))
' this does the same as above but parse the second line of
' text in the clipboard.
N = InStr(InStr(1, Lines(1), "(", vbBinaryCompare) + 1, Lines(1), "(")
S = Mid(Lines(1), N + 1, Len(Lines(1)) - N - 1)
LineContent = Split(S, ",")
' End1 and End2 are the values in the second line of text
' in the clipboard.
End1 = CDbl(LineContent(0))
End2 = CDbl(LineContent(1))
' display the results
Debug.Print "Starts:", Start1, Start2
Debug.Print "Ends:", End1, End2
End Sub
You can find information and code for working with the clipboard atwww.cpearson.com/Excel/Clipboard.aspx. The rest of the code is just a
careful application of the standard text functions.
Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLCwww.cpearson.com
[email on web site]
I have data on the clipboard of a specific format:
Start: (') (915855.639280, 638485.145786)
End: (') (917162.295718, 637714.747829)
I would like to bring this from the windows clipboard into a variable
in which I can parse it (to extract and use the coordinates). I can't
find this when I search groups and whatnot. Can anyone help me with
this?
- Paul
Schrum
Raleigh, NC- Hide quoted text -
- Show quoted text -