Attribute VB_Name = "JoshMacros" Sub PasteLine() ' ' strips out CR and LF characters from clipboard text, ' then inserts 'clean' version into text. ' ' more notes at the end. ' ' v1.0 josh whitkin josh+sourceforge@mosswoodbuilders.com ' Dim q() As Byte 'clipboard char array Dim z() As Byte 'target char array Dim i As Long 'counter of q Dim j As Long 'counter of z Dim x As String 'temp string Dim onefound As Boolean 'this flag tells us if the last character was a LF or not Dim y As DataObject Set y = New DataObject 'DataObjects have more basic access to clipboard, unlike the 'default' VBA clipboard handling objects like Selection() y.GetFromClipboard 'Grabs clipboard as an object (pic, text, whatever) x = y.GetText(1) 'gets text string of clipboard z = StrConv(x, vbFromUnicode) 'strConv converts a string into an array of bytes q = z 'our target string starts as a copy of the source. j = 0 ' j is an index, also used as the end of the 'true' target string. For i = 0 To UBound(z) If Not (z(i) = 13 Or z(i) = 10) Then q(j) = z(i) j = j + 1 Else 'This hasn't been debugged yet, so it's commented out for now. ' 'the goal here is to detect two consecutive CR/LF pairs, and leave one of them in. ' If onefound And z(i) = 13 Then ' q(j) = z(i) ' j = j + 1 ' End If ' If z(i) = 10 Then onefound = True ' End If Next x = "" 'reuse x as final output string ' j is reused as the end of the 'true' target string. For i = 0 To j - 1 'we truncate the other string at j because it'll have extra chars at the end, since it was the same length as input string x = x + Chr(q(i)) 'chr converts ASCII byte code to its character. so we build teh output string, char by char. Next Selection.TypeText (x) End Sub ' MORE NOTES ' ' I realize I've implemented an incredibly stupid method to accomplish what I wanted, but it was the only way I could make work. ' I originally tried to write this using built-in VBA functions such as Find() but two problems: ' First, I couldn't get them to search for special characters like CR/LF, ' Second, I couldn't access the clipboard text without inserting it, raw, into the document ' Third, I couldn't select the text I had just inserted into a document.