Remove formatting when displaying autotext in textbox

D

Dan

From what I've been able to figure out, textboxes (userform) in VBA have a limit of 64k. So, when I go try to insert some of my autotext entries into a textbox (basically using the textbox as a "preview pane" for autotext entries), they almost always get cut off. Most entries are just plain text, about 40 lines (paragraph returns) or so. I assume that what is making these autotext entries so large (over the 64k) is the various formatting, styles, etc. that get saved with the autotext, even though it is really just meant to be plain text. Is there a way I can display the item in a textbox while removing the formatting? Right now I just use txtbox.Text = txttemplate.AutoTextEntries(AutoTextEntry

This works fine, except like I said, it cuts it off. It seems that VB has a RichTextBox type, but VBA does not appear to have such a thing. If you're inserting autotext in a document, you can define richtext to be true or false, anyway to do that here? Could the autotext be assigned to a variable first, and then the variable converted to just text? Could something other than a textbox be used? Any ideas
 
J

Jay Freedman

Hi Dan

You're barking up the wrong tree. It has nothing to do with
formatted/unformatted/richtext. It's just that -- for reasons only the
MS VBA team know -- an AutoTextEntry has the following limitation
(quoted from the VBA help topic on the Value property):

<<<<<
For AutoCorrectEntry and AutoTextEntry objects, the Value property
only returns the first 255 characters of the object's value. Setting
the Value property to a string longer than 255 characters generates an
error.
<<<<<

When you use the expression txtbox.Text =
txttemplate.AutoTextEntries(AutoTextEntry), you're implicitly using
the Value property, and that's why your text is truncated.

If you use the Insert method to put the AutoTextEntry into a document,
there is no such limitation. So the workaround is to temporarily stick
the ATentry into the document, grab it into a string, and Undo to get
rid of the text from the document. Then you can throw the string into
the textbox and you'll get the whole thing.

Try this example in a userform with a textbox (tbxText), and change
the name "bigstuff" to the name of your ATentry...

Private Sub UserForm_Initialize()
Dim strTemp As String
Dim rgTemp As Range

Set rgTemp = ActiveDocument.Range
rgTemp.Collapse wdCollapseEnd

Set rgTemp = _
txttemplate.AutoTextEntries("bigstuff") _
.Insert(Where:=rgTemp, RichText:=False)
strTemp = rgTemp.Text
ActiveDocument.Undo
Set rgTemp = Nothing
tbxText.Text = strTemp
End Sub
 
D

Dan

Ahh, well, that makes sense then, looks like I WAS in the wrong tree, LOL. I was afraid I would end up having to do the whole insert into document, then into variable routine. Looks like that will be the only way to do it. Should be instant, but imagine I'll just turn off screenupdating for the half second it takes. Thanks a lot for your help =

----- Jay Freedman wrote: ----

Hi Da

You're barking up the wrong tree. It has nothing to do wit
formatted/unformatted/richtext. It's just that -- for reasons only th
MS VBA team know -- an AutoTextEntry has the following limitatio
(quoted from the VBA help topic on the Value property)

<<<<
For AutoCorrectEntry and AutoTextEntry objects, the Value propert
only returns the first 255 characters of the object's value. Settin
the Value property to a string longer than 255 characters generates a
error
<<<<

When you use the expression txtbox.Text
txttemplate.AutoTextEntries(AutoTextEntry), you're implicitly usin
the Value property, and that's why your text is truncated

If you use the Insert method to put the AutoTextEntry into a document
there is no such limitation. So the workaround is to temporarily stic
the ATentry into the document, grab it into a string, and Undo to ge
rid of the text from the document. Then you can throw the string int
the textbox and you'll get the whole thing

Try this example in a userform with a textbox (tbxText), and chang
the name "bigstuff" to the name of your ATentry...

Private Sub UserForm_Initialize(
Dim strTemp As Strin
Dim rgTemp As Rang

Set rgTemp = ActiveDocument.Rang
rgTemp.Collapse wdCollapseEn

Set rgTemp =
txttemplate.AutoTextEntries("bigstuff")
.Insert(Where:=rgTemp, RichText:=False
strTemp = rgTemp.Tex
ActiveDocument.Und
Set rgTemp = Nothin
tbxText.Text = strTem
End Su

Dan said:
From what I've been able to figure out, textboxes (userform) in VBA have a limit of 64k. So, when I go try to insert some of my autotext entries into a textbox (basically using the textbox as a "preview pane" for autotext entries), they almost always get cut off. Most entries are just plain text, about 40 lines (paragraph returns) or so. I assume that what is making these autotext entries so large (over the 64k) is the various formatting, styles, etc. that get saved with the autotext, even though it is really just meant to be plain text. Is there a way I can display the item in a textbox while removing the formatting? Right now I just use txtbox.Text = txttemplate.AutoTextEntries(AutoTextEntry


-
Regards
Jay Freedma
Microsoft Word MVP FAQ: http://www.mvps.org/wor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top