zelarra821
Registered User.
- Local time
- Today, 18:36
- Joined
- Jan 14, 2019
- Messages
- 860
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.
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?
Thank you very much.
Code:
<?xml version="1.0" encoding="utf-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<ribbon startFromScratch="true">
<tabs>
<tab id="T001" label="Formato de texto">
<group idMso="GroupTextFormatting">
</group>
<group id="PegadoEspecial" label="PegadoEspecial">
<button id="PegarTextoSinFormato" label="PegarTextoSinFormato" imageMso="MasterViewClose" size="large" supertip="Pegar texto sin formato" onAction="rbPegarSinFormato" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
Code:
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?
Thank you very much.