When I create a msgbox in VBA, the user cannot interact with the text at all. In my case, I want the user to be able to highlight and copy the text. I'm thinking the better way to do this may be to add a button that copies the text to the clipboard. Any suggestions?
Asked
Active
Viewed 4.7k times
28
-
2Have you considered to make a custom message box form? – Joe DF Aug 30 '12 at 02:28
-
If I was more experienced in VBA and knew how to, that sounds like the path I'd go down. However, my experience is small and, as it is, my time is quite limited. – nobillygreen Aug 30 '12 at 03:06
5 Answers
47
For this code:
msgbox "Does Control+C work on a lowly, old message box?"
you can press ctrl + c, open notepad, ctrl + v and you will get this:
---------------------------
Microsoft Excel
---------------------------
Does Control+C work on a lowly, old message box?
---------------------------
OK
---------------------------

ray
- 8,521
- 7
- 44
- 58
13
If you want text that is "selectable" then don't use MsgBox. Use a Custom form and instead of a label use a textbox. However...
Change these properties of the textbox in design mode.
- SpecialEffect - fmiSpecialEffectFlat
- BackStyle - Transparent
- Locked - True
And then use this code
Option Explicit
Private Sub UserForm_Initialize()
Me.Caption = "Message Box"
TextBox1.Text = "Hello World!"
End Sub

kmote
- 16,095
- 11
- 68
- 91

Siddharth Rout
- 147,039
- 17
- 206
- 250
-
+1 Any ideas on how to deal with multi-line messages? `WordWrap = True` doesn't seem to make the text actually wrap. – Jean-François Corbett Aug 30 '12 at 06:48
-
2
-
4
You could use VBA to set the clipboard text if the user typically would copy the entire message.
Or use input box instead of msgbox, since the user can copy from the populated value.

Tim Williams
- 154,628
- 8
- 97
- 125
4
You could make your own custom message box using a UserForm. Here's a rudimentary proof-of-concept: a userform with one text box (from which you can select and copy text).
Sub MyMsg(msg As String)
With MsgUserForm ' this is the name I gave to the userform
.TextBox1.Text = msg
.Show
End With
End Sub
Usage:
MyMsg "General failure reading hard drive."

Jean-François Corbett
- 37,420
- 30
- 139
- 188