# Clipboard RTF Data on Windows

**URL:** <https://forum.xojo.com/t/clipboard-rtf-data-on-windows/84552>\
**Category:** Windows\
**Created:** [March 12, 2025, 3:11pm UTC](https://forum.xojo.com/t/clipboard-rtf-data-on-windows/84552 "2025-03-12T15:11:14Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Halford](https://forum.xojo.com/user_avatar/forum.xojo.com/chris_halford/32/480_2.png) [@Chris\_Halford](https://forum.xojo.com/u/Chris_Halford)\
**Post date:** [March 12, 2025, 3:11pm UTC](https://forum.xojo.com/t/clipboard-rtf-data-on-windows/84552/1 "2025-03-12T15:11:14Z")

</div>

OK, this is driving me batty now. How can I set RTF data on the Windows Clipboard?

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [March 12, 2025, 3:48pm UTC](https://forum.xojo.com/t/clipboard-rtf-data-on-windows/84552/2 "2025-03-12T15:48:35Z")

</div>

You need **[WindowsClipboardMBS](https://www.monkeybreadsoftware.net/class-windowsclipboardmbs.shtml).RegisterClipboardFormat** to get RTF code and then put it on the clipboard with that type.

---

<div class="post-metadata">

**Author:** ![Chris\_Halford](https://forum.xojo.com/user_avatar/forum.xojo.com/chris_halford/32/480_2.png) [@Chris\_Halford](https://forum.xojo.com/u/Chris_Halford)\
**Post date:** [March 12, 2025, 4:17pm UTC](https://forum.xojo.com/t/clipboard-rtf-data-on-windows/84552/3 "2025-03-12T16:17:38Z")

</div>

I read though the documentation and the example in the RegisterClipboardFormat

```auto
Var theFormat As Integer = WindowsClipboardMBS.RegisterClipboardFormat("Rich Text Format")
Var isAvaialble As Boolean = WindowsClipboardMBS.IsClipboardFormatAvailable(theFormat)

```

This returns a negative value for theFormat, isAvailable is false, and trying to setData returns false.

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [March 12, 2025, 4:18pm UTC](https://forum.xojo.com/t/clipboard-rtf-data-on-windows/84552/4 "2025-03-12T16:18:53Z")

</div>

> [@Chris\_Halford](#):
>
> How can I set RTF data on the Windows Clipboard?

A simple search of the line above returned tons of entries; notably:

[Clipboard Formats](https://learn.microsoft.com/en-us/windows/win32/dataxchg/clipboard-formats)  
and

[Clipboard](https://learn.microsoft.com/en-us/dotnet/visual-basic/developing-apps/programming/computer-resources/storing-data-to-and-reading-from-the-clipboard)

---

<div class="post-metadata">

**Author:** ![Chris\_Halford](https://forum.xojo.com/user_avatar/forum.xojo.com/chris_halford/32/480_2.png) [@Chris\_Halford](https://forum.xojo.com/u/Chris_Halford)\
**Post date:** [March 12, 2025, 4:38pm UTC](https://forum.xojo.com/t/clipboard-rtf-data-on-windows/84552/5 "2025-03-12T16:38:44Z")

</div>

and it looks like that is the right way to do it.  
There isn’t a “getLastError” on the MBS Plugin, so I’m at a loss for how to fix it - tried a bunch of variations but no good.

---

<div class="post-metadata">

**Author:** ![kevin\_g](https://forum.xojo.com/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kevin\_g](https://forum.xojo.com/u/kevin_g)\
**Post date:** [March 12, 2025, 4:48pm UTC](https://forum.xojo.com/t/clipboard-rtf-data-on-windows/84552/6 "2025-03-12T16:48:26Z")

</div>

Here is a snippet of code from one of our apps.

```auto
clipboardObj = New Clipboard

#If TargetMacOS Then
  clipboardObj.AddRawData(rtfData, "RTF ")
#Else
  clipboardObj.AddRawData(rtfData, "Rich Text Format")
#EndIf

clipboardObj.Close

```

Note. We also set the Text property to a non-styled version of the text before we add the raw data. I am unsure if you would need to do that to enable the adding of raw data.

```auto
clipboardObj = New Clipboard
clipboardObj.Text = plaintText

#If TargetMacOS Then
  clipboardObj.AddRawData(rtfData, "RTF ")
#Else
  clipboardObj.AddRawData(rtfData, "Rich Text Format")
#EndIf

clipboardObj.Close

```

---

<div class="post-metadata">

**Author:** ![Chris\_Halford](https://forum.xojo.com/user_avatar/forum.xojo.com/chris_halford/32/480_2.png) [@Chris\_Halford](https://forum.xojo.com/u/Chris_Halford)\
**Post date:** [March 12, 2025, 5:07pm UTC](https://forum.xojo.com/t/clipboard-rtf-data-on-windows/84552/7 "2025-03-12T17:07:10Z")

</div>

Thank you.  
I’ve implemented that and I can paste the text version but I cannot get the RTF to paste in anywhere.  
But… It does paste the unformatted text, so it doesn’t break anything.

---

<div class="post-metadata">

**Author:** ![kevin\_g](https://forum.xojo.com/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kevin\_g](https://forum.xojo.com/u/kevin_g)\
**Post date:** [March 12, 2025, 5:15pm UTC](https://forum.xojo.com/t/clipboard-rtf-data-on-windows/84552/8 "2025-03-12T17:15:45Z")

</div>

Are you sure your RTF is valid?

---

<div class="post-metadata">

**Author:** ![Chris\_Halford](https://forum.xojo.com/user_avatar/forum.xojo.com/chris_halford/32/480_2.png) [@Chris\_Halford](https://forum.xojo.com/u/Chris_Halford)\
**Post date:** [March 12, 2025, 5:28pm UTC](https://forum.xojo.com/t/clipboard-rtf-data-on-windows/84552/9 "2025-03-12T17:28:42Z")

</div>

I am. It comes from a text area and this works perfectly on Mac.  
When I was iterating the possible solutions the best I could do was get it to copy the RTF data as plain text, and I validated that it was right on Win as well.  
Of course, I could be missing something simple.

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [March 12, 2025, 5:54pm UTC](https://forum.xojo.com/t/clipboard-rtf-data-on-windows/84552/10 "2025-03-12T17:54:18Z")

</div>

Well, have you tried to copy some RTF in another app and then inspect the clipboard?  
e.g. by enumerating what is in the clipboard?

---

<div class="post-metadata">

**Author:** ![Chris\_Halford](https://forum.xojo.com/user_avatar/forum.xojo.com/chris_halford/32/480_2.png) [@Chris\_Halford](https://forum.xojo.com/u/Chris_Halford)\
**Post date:** [March 12, 2025, 6:32pm UTC](https://forum.xojo.com/t/clipboard-rtf-data-on-windows/84552/11 "2025-03-12T18:32:36Z")

</div>

Yep, and Rich Text Format shows up.

When I call this I get -28  
Var id As Integer= WindowsClipboardMBS.RegisterClipboardFormat(“Rich Text Format”)

then when I cal ClipBoardFormats it shows 28 (not negative)

I’ve tried doing the SetData with the returned value and it’s abs, but still no joy.  
When I call GetClipBoardFormatName it comes back blank.

I don’t think this is me. Is it possible there is a bug?

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [March 12, 2025, 6:38pm UTC](https://forum.xojo.com/t/clipboard-rtf-data-on-windows/84552/12 "2025-03-12T18:38:23Z")

</div>

Sorry, you found a bug in the plugin. I made a mess with the data types and caused an integer overflow ☹  
I’ll fix the plugin.

---

<div class="post-metadata">

**Author:** ![Chris\_Halford](https://forum.xojo.com/user_avatar/forum.xojo.com/chris_halford/32/480_2.png) [@Chris\_Halford](https://forum.xojo.com/u/Chris_Halford)\
**Post date:** [March 12, 2025, 6:51pm UTC](https://forum.xojo.com/t/clipboard-rtf-data-on-windows/84552/13 "2025-03-12T18:51:36Z")

</div>

That’s great to know.  
Thanks, Christian!

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [March 12, 2025, 7:04pm UTC](https://forum.xojo.com/t/clipboard-rtf-data-on-windows/84552/14 "2025-03-12T19:04:15Z")

</div>

New plugin here:  
[https://www.dropbox.com/scl/fo/714hvwzr2rqjp3bukepuk/AHWokqR5QaB62WEHiik-FSo?rlkey=ufslamodl084gj844uuq7wgfl&dl=0](https://www.dropbox.com/scl/fo/714hvwzr2rqjp3bukepuk/AHWokqR5QaB62WEHiik-FSo?rlkey=ufslamodl084gj844uuq7wgfl&dl=0)

To enumerate formats:

```auto
// show list of all formats
var w as new WindowsClipboardMBS

var formats() as string
var f as integer = w.EnumClipboardFormats(0)
while f <> 0
  formats.Add f.ToString+": "+w.GetClipboardFormatName(f)
  
  f = w.EnumClipboardFormats(f)
wend

MessageBox join(formats, EndOfLine)

```

get the RTF data:

```auto
Var TypeRTF as Integer = WindowsClipboardMBS.RegisterClipboardFormat("Rich Text Format")
var w as new WindowsClipboardMBS

if w.IsClipboardFormatAvailable(TypeRTF) then
  var rtf as string = w.GetData(TypeRTF)
  
  Break
  
end if

```

Seems to work fine now.

---

<div class="post-metadata">

**Author:** ![Chris\_Halford](https://forum.xojo.com/user_avatar/forum.xojo.com/chris_halford/32/480_2.png) [@Chris\_Halford](https://forum.xojo.com/u/Chris_Halford)\
**Post date:** [March 12, 2025, 7:15pm UTC](https://forum.xojo.com/t/clipboard-rtf-data-on-windows/84552/15 "2025-03-12T19:15:23Z")

</div>

That’s awesome.  
Thank you very much.
