View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Edward Ulle Edward Ulle is offline
external usenet poster
 
Posts: 92
Default Please, help with concatenation

Its hard to tell exactly what gets copied to the clipboard but assuming
the first word should be in column A and the rest in column B try this.
It also assumes the delimiter is a space character. You may have to
experiment.

To run it simply go to your PDF document and copy the text to the
clipboard. Now go to Excel and assuming the active sheet is the right
one run the macro and the text will be placed in worksheet.

You can adjust the destination range accordingly.

Option Explicit

' Add reference to Microsoft Forms 2.0 Object Library

Sub Test()

Dim myDataObject As DataObject
Dim strText As String
Dim vArray As Variant
Dim i As Integer
Dim j As Integer

Set myDataObject = New DataObject

myDataObject.GetFromClipboard
strText = myDataObject.GetText(1)

vArray = Split(Expression:=strText, Delimiter:=" ",
Compa=vbTextCompare)

j = 0
strText = vbNullString
For i = LBound(vArray) To UBound(vArray)
If Len(Trim(vArray(i))) Then ' Check if empty string
If j = 0 Then
Range("A1").Offset(0, 0) = vArray(i)
j = j + 1
ElseIf j = 1 Then
strText = vArray(i)
j = j + 1
Else
strText = strText + " " + vArray(i)
End If
End If
Next
Range("A1").Offset(0, 1) = strText
Range("A1").Offset(0, 1).WrapText = False

Set myDataObject = Nothing

End Sub




*** Sent via Developersdex http://www.developersdex.com ***