我有一個宏,我想用它來允許用戶粘貼電子郵件中的文本,並自動識別和組織信息以填寫表單。Excel VBA插入InputBox粘貼大文本
我的問題是當談到簡化「粘貼」過程。
我的想法是插入一個InputBox或一個UserForm,用戶將能夠粘貼整個電子郵件文本。雖然它沒有按照我的預期工作。
通常當您在範圍(「A2」)中使用CTRL + V(比方說)時,文本將像電子郵件一樣逐行分開。
是否可以做同樣的事情,但與框提示?還是它只允許插入少量的數據並且只能在一行中?
我的代碼1)
EmailText = InputBox("Please insert Email Text Below")
wsRep.Range("A2").Value = EmailText
「這僅複製第一行
同樣的問題與提示用戶窗體 - NameTextBox
任何人都可以,請告知任何其他方式做到這一點?
(我想避免用戶有工作表或做什麼,但粘貼之間切換)提前
非常感謝。
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
對於UserForm,您是否設置了文本框的Multiline屬性?默認值爲false,您應該將其設置爲true。 –