Hello everyone,

I'm new here on this forum. I read lots of topics before I registered myself.
I'm quite new on VBA programming. Although I understand the basics I've sometimes some difficulties to discover the right expressions to get what I want.

At this moment I'm on a little project to make a messaging tool for communication ground-air.
In this tool I've a text box in which one is able to typ a message for air crew. The problem is (multi line is set on) that the whole message will appear on 1 line in the final message. The visible line breaks in the text box aren't real line breaks. I would like to have an automated line break after every 40 characters (spaces included) every time the text exceeds 40 characters.

I came up with this code which, of course, doesn't work:

Formula: copy to clipboard
Sub MessageBox2_Change()

Dim MaxChar As String

MaxChar = 40
If MessageBox2.MaxLength > MaxChar Then MessageBox2.Value = vbNewLine

End Sub


The question is: why? I would like to have VBA put a "vbNewLine" (new line) every time the character amount exceeds 40. Its seems to be more difficult than I thought. Or maybe I'm close, but took a wrong code somewhere.


Thanks a lot!

Paul