1
votes

i have a problem with an userform on excel. In the userform i have a textbox2 that value is a result of some combobox. then i changed the format font of the textbox2 from the property and that's work when i have the results the textbox2 shows the correct font but if i copy it with CTRL+C and the try to paste on excel or outlook mail the font changes in calibri... why this happen? i also tryed with automatic copytoclipboard i'll paste the code.

   Dim clipboard As MSForms.DataObject
Set clipboard = New MSForms.DataObject
clipboard.SetText Me.TextBox2.Text
clipboard.PutInClipboard

That's works, because if i press CTRL+V it paste the result in textbox2 anyway it changes the font format...

Thanks in advance!

PS: i prefer to find a solution that permit me to copy manually from the textbox2 keeping the font format, but if it's impossible a code solution will be fine too. thanks a lot!

2
anyway i haven't cells.. because i haven't sheets. I use this userform only as userform the result will be copy in others excel files. so i can't operate in cells or excel files.Merlin38

2 Answers

0
votes

You are confusing things.

A textbox on a userform has a Font property, which you can set/read manually or with code (see the answer by Benno).

But this font name is not part of the text that is entered into that textbox. The textbox only stores plain text, and this is all you get when copying from it.

Therefore, when you paste this into another document, it will use the default or current font of that document (usually Calibri for Office documents).

You can download Free Clipboard Viewer which shows the various formats in the clipboard after copying something. It is quite different when copying plain text (from a text editor or from the textbox) or formatted text (from a webpage or from Word).

So: you can't copy the font information from a textbox.

0
votes

You can set the font of the Cells to the font of the TextBox (This should at least work for excel)

Range("A1").Font.Name = TextBox2.Font       'A1 is only an example

Also you can try to create a macro that runs this whenever the cells are changed (Workbook_Change) Look here for more information.