OK, perfect. I have created a ribbon with two tabs, one with the default group of Paragraph Formatting, and another tab with a button for Plain Paste. Everything works correctly, but the behavior needs to be fine-tuned.
Sub rbPegarSinFormato(Control As IRibbonControl)
Screen.ActiveControl = Screen.ActiveControl + vbLf + Application.PlainText(Clipboard)
End Sub
Function Clipboard(Optional StoreText As String) As String
'PURPOSE: Read/Write to Clipboard
'Source: ExcelHero.com (Daniel Ferry)
Dim x As Variant
'Store as variant for 64-bit VBA support
x = StoreText
'Create HTMLFile Object
With CreateObject("htmlfile")
With .parentWindow.clipboardData
Select Case True
Case Len(StoreText)
'Write to the clipboard
.setData "text", x
Case Else
'Read from the clipboard (no variable passed through)
Clipboard = .GetData("text")
End Select
End With
End With
End Function
I detail what happens:
1. When I paste the text, it ends up selecting all the text, and I want it to stay at the beginning or at the end, it doesn't matter to me.
2. When there is no text in the field, having put a paragraph break, it adds a paragraph and then the text. Here we should put a conditional that says that if the field is empty, that it only adds the copied text without formatting; but if the field is filled, it adds a paragraph mark (I've put a constant, but it doesn't add a paragraph) and the plain text.
3. In the ribbon, I want to add an image to the custom button, but I don't know how it is. Can you explain me?
dim ctrl as access.control
set ctrl = me.activecontrol
ctrl.selstart = len(ctrl.text)
ctrl.selLength = 1
2. When there is no text in the field, having put a paragraph break, it adds a paragraph and then the text. Here we should put a conditional that says that if the field is empty, that it only adds the copied text without formatting; but if the field is filled, it adds a paragraph mark (I've put a constant, but it doesn't add a paragraph) and the plain text.
Code:
if (me.activecontrol.text & "") = "" then
me.ActiveControl.text & Application.PlainText(Clipboard)
else
Me.ActiveControl.text & vbLf & Application.PlainText(Clipboard)
end if
3. In the ribbon, I want to add an image to the custom button, but I don't know how it is. Can you explain me?
I would ask in a separate thread. I am not good at Ribbons but there are others on the site that are very good.
From the image, it was only to change it in what I have happened to you: I have put paste and it has already taken the one I wanted.
One last question: I'm trying to get it to create a separate new line for me, and there's no way. I have tried with vbCrLf, vbCr, vbLf and vbNewLine, but none creates a separate line for me
Sub rbPegarSinFormato(Control As IRibbonControl)
If (Screen.ActiveControl & "") = "" Then
Screen.ActiveControl = Screen.ActiveControl + Application.PlainText(Clipboard)
Else
Screen.ActiveControl = Application.HtmlEncode(Application.PlainText(Screen.ActiveControl & "<br>" & Clipboard))
End If
Dim ctrl As Access.Control
Set ctrl = Screen.ActiveControl
ctrl.SelStart = Len(ctrl.Text)
End Sub