I have a macro which I want to use to allow users to paste text from an Email and will automatically recognize and organize the information for filling up forms.
My problem is when it comes to make simple the "paste" process.
My idea was to insert an InputBox or a UserForm where user will be able to paste the whole Email Text. Although it didnt work out as I was expecting.
Normally when you use CTRL+V (let's say) in Range("A2"), the text will split line by line as in the email.
Is it possible to do the same but with a box prompt? Or does it only allows to insert few bits of data and only in 1 line?
My code 1)
EmailText = InputBox("Please insert Email Text Below")
wsRep.Range("A2").Value = EmailText
'It only copies the first line
Same issue with the Prompt UserForm - NameTextBox
Could anyone please advise any other way to do it?
(I want to avoid users to have to switch between worksheets or doing anything but pasting)
Many thanks in advance.
SOLUTION:
Dim oDO As DataObject
Dim tmpArr As Variant
Dim Cell As Range
Set oDO = New DataObject
'First we get the information from the clipboard
If MsgBox("Please copy the text from the email and then press OK", vbOKCancel) = vbOK Then
oDO.GetFromClipboard
'Here we send the ClipBoard text to a new string which will contain all the Information (all in 1 line)
sTxt = oDO.GetText
wsRep.Range("A2") = sTxt 'Range is up to you
'Now we can split the email information using the "line break" and this code (found it [here][1])
Application.Goto Reference:=wsRep.Range("A1") 'I need to move to the worksheet to run this code
'This code split each line using the criteria "break line" in rows
For Each Cell In wsRep.Range("A2", Range("A2").End(xlDown))
If InStr(1, Cell, Chr(10)) <> 0 Then
tmpArr = Split(Cell, Chr(10))
Cell.EntireRow.Copy
Cell.Offset(1, 0).Resize(UBound(tmpArr), 1). _
EntireRow.Insert xlShiftDown
Cell.Resize(UBound(tmpArr) + 1, 1) = Application.Transpose(tmpArr)
End If
Next
Application.CutCopyMode = False
End If