PDA

View Full Version : TYPING INTO TEXTBOXES



Greg
05-20-2007, 09:28 PM
Hi All,

I used to think that text typed into a textbox would always continue in a single line and would not wrap to the next line of the textbox just as it does in the box that I am typing into now.

However, I have seen an instance where the text does wrap to the next line and now wish to achieve that result myself. Can anyone assist by providing the necessary code.

I hope someone can help.

Regards,

Greg.

geekgirlau
05-20-2007, 10:10 PM
Are you referring to the drawing object text box? If so, double-click on the border of the text box, select the "Text Box" tab and check "Word wrap text in AutoShape".

Greg
05-20-2007, 10:29 PM
Hi Geekgirl,

I tried that without success. I would like to attach my document but I am having difficulty doing that as well.

I have selcted Wordwrap as suggested and chosen "true". It makes not difference.

geekgirlau
05-21-2007, 12:07 AM
Are you able to copy the text box to a new document and attach that to your post? If you click on "Go Advanced" you can then use the "Manage Attachments" button to do this.

Greg
05-21-2007, 12:50 AM
Something is wrong with our system. Awfully slow today.

geekgirlau
05-21-2007, 01:20 AM
Where is the text box?

Greg
05-21-2007, 01:43 AM
Press the active X button near the top right hand side of the document.

geekgirlau
05-21-2007, 02:26 AM
OK, you have Word Wrap set to TRUE, but you also need MultiLine set to TRUE

Greg
05-21-2007, 05:52 PM
Hi Geek girl,

Thank you very much. That works beautifully.

However, I had also hoped (perhaps naively) that I could create separate paragraphs in the text entered into the textbox. That doesn't seem possible.

Do you know of any way the text can be broken up?

Greg.

geekgirlau
05-21-2007, 06:21 PM
Change "EnterKeyBehaviour" to TRUE

Greg
05-21-2007, 07:26 PM
That's bloody marvellous. The next dumb question is this: Is it also possible to make a hanging indent?

I successfully entered Ctrl T to create a tab but I couldn't get the remaining text in the paragraph to indent to that tab position. I would normally do this in a Word document by using Ctrl T followed by Ctrl Tab. Is this possible?

Many thanks.

Greg.

geekgirlau
05-21-2007, 08:39 PM
If you set the TabKeyBehaviour to TRUE, you can use [Tab] in the text box, but you can't duplicate the hanging indent (or even a normal indent for that matter). However you can always apply the hanging indent after you insert the text into the document.

Greg
05-21-2007, 08:53 PM
Thank you.

I may have to consider a workaround - maybe a column to the left of my text with paragraph numbers in it. I would then have to work out how to number the paragraphs and make them align correctly with the text.

Do you have any ideas or suggestions in that regard?

Greg.

geekgirlau
05-21-2007, 09:33 PM
Start with a plain paragraph in Word, start recording a macro and format your paragraph - this will give you the correct syntax for your code. If I understand you correctly, you should be able to use standard paragraph numbering and indenting for this. My point is merely that you can't do the indenting within the text box, only with the document itself.

Greg
05-21-2007, 09:58 PM
Ok but I have another problem. My bookmark keeps shifting further and further down through the document. That is, when I press ok on the userform, the end bracket of the bookmark makes its way out of the table or cell I'm working in and keeps shifting downward, at times completely outside the table.

fumei
05-21-2007, 09:58 PM
Have to say, this seems a very odd thing to do.

Greg
05-23-2007, 10:21 PM
Hi again Geek girl.

I have attached my document so that you can see the problem I have with using the Enter and Ctrl Tab combinations in the textbox for indorsements.

The first line will always be ok but adding successive line makes the problem progressively worse. That is, the bookmark will make its way to other parts of the document outside the cell it belongs to.

I'm all out of ideas on this but you may have some tricks up your sleeve.

Regards,

Greg.

geekgirlau
05-24-2007, 01:04 AM
I would recommend that you don't attempt to do the numbering and tabs/indenting in the text box, but apply it after you insert the text in the document.

In your procedure "FillABookmark", add some code where if the name of the bookmark is "Indorsement", whilst the text is highlighted you add paragraph numbering. You should be able to record the steps to format the text as you want it to appear. That way the user only has to press Enter to start a new line, and not worry about the format of the end result.


Sub FillABookmark(strBM_Name As String, strBM_Text As String)
Dim ThisDoc As Word.Document


Set ThisDoc = ActiveDocument
' following is for formfields, if no formfields can remove
If ThisDoc.ProtectionType = wdAllowOnlyFormFields Then
ThisDoc.Unprotect
End If

On Error Resume Next
With Selection
.GoTo What:=wdGoToBookmark, Name:=strBM_Name
.Collapse Direction:=wdCollapseEnd
ThisDoc.Bookmarks(strBM_Name).Range.Text = strBM_Text
.MoveEnd unit:=wdCharacter, Count:=Len(strBM_Text)
ThisDoc.Bookmarks.Add Name:=strBM_Name, Range:=Selection.Range

If strBM_Name = "Indorsement" Then
' format the text for paragraph numbering here
End If

.Collapse Direction:=wdCollapseEnd
End With

' to reset formfields
If ThisDoc.FormFields.Count > 0 Then
ThisDoc.Protect wdAllowOnlyFormFields, Password:=""
End If

Set ThisDoc = Nothing
End Sub

fumei
05-24-2007, 11:07 PM
Wow, it is so weird to see someone using and posting my code. I posted FillABookmark so long ago. Cool.

Greg
05-25-2007, 12:02 AM
Your code is great Gerry. If you feel that enhancing it in any way don't hold back now.

Greg
05-28-2007, 07:28 PM
Hi Geek girl,

I applied a shortcut Alt+1 to the style I want to apply to the paragraphs in the "Indorsment" of the document. I had hoped that pressing "Enter" after each paragraph in the textbox I would get the desired result. Alas, the bookmark still works its way to the outside of the table cell.

I also tried recording the shortcut procedure "Alt+1" and placing the code into the module as described in your last message. That code took over the whole document and just about all the text in the doucment had the chosen style applied to it.

I am at a loss here and need more instruction. Please forgive me. I hope you can help.

Greg.

lucas
05-28-2007, 08:16 PM
Wow, it is so weird to see someone using and posting my code. I posted FillABookmark so long ago. Cool.
We've been yoinking your code for a long time Gerry.....:devil2:
I would never have figured out how to put text into bookmarks without following your posts....Word is so different from Excel.

geekgirlau
05-28-2007, 08:27 PM
Greg, can you post your latest version of the document?

Greg
05-28-2007, 09:10 PM
Here it is. This document has my changes in it but soemthing isn't quite right at present. I'm sure it will be very obvious to you.

Greg.

geekgirlau
05-28-2007, 10:10 PM
Okay, I suspect what is happening here is that the paragraph numbering is affecting the calculation Word uses for the length of the text string.

In having a look at the document, it seems that all of the bookmarks appear in a cell on their own. If this is correct, what about selecting the entire cell, then back one character, rather than selecting forward for the number of characters in the text. In other words, replace

.MoveEnd unit:=wdCharacter, Count:=Len(strBM_Text)

with

.SelectCell
.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend

Greg
05-28-2007, 11:09 PM
Thanks Geek girl. That's getting there but I have a new problem.

Because I used a numbering "style" the paragraph numbers change automatically as I hoped they would but the numbers continue to rise throughout the ref fields on other pages of the document. And, the last paragraph does not appear as a numbered paragraph at all.

Once more, your help will be greatly appreciated.

The amended document is attached.

Greg.

geekgirlau
05-29-2007, 05:42 PM
You'll need to manually restart the numbering. I would suggest that you set a bookmark where the REF field appears, so your code can go to that bookmark and use Format | Bullets and Numbering | Restart to set the number to 1.

The last line in the REF field will only have a number if you press Enter after the last line in the "Indorsement" bookmark, so you need to check that the last character in the bookmark is a paragraph mark.