PDA

View Full Version : how to align text in textbox



saban
03-08-2008, 02:22 PM
how to align text in textbox
My variable contains data:

kjhgkhkhk saban 360 Completed
pol@ghfghfhfghgfhfghmail.com saban 30 Not started
saban123 saban 105 Not started

How do I dispaly them on list like this:
kjhgkhkhk __________________saban 360 Completed
pol@ghfghfhfghgfhfghmail.com saban 30 Not started
saban123 __________________saban 105 Not started

So it is more readable
I this possible with textbox should I use something else I am lost here

fumei
03-10-2008, 09:29 AM
I am lost in what you are asking.

What variable??

I do not get the connection between textbox, and a list.

Tinbendr
03-10-2008, 02:23 PM
How about this?

Sub ChangeToTab()
Dim Rng As Range
Dim MyTab As Variant
Set Rng = ActiveDocument.Range
Rng.Find.Execute findtext:=" ", replacewith:=vbTab, _
Forward:=True, Replace:=wdReplaceAll
Rng.Collapse wdCollapseStart
Rng.ParagraphFormat.TabStops.Add Position:=InchesToPoints(2.5), _
Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpace
Set MyTab = ActiveDocument.Paragraphs(1).TabStops
ActiveDocument.Paragraphs.TabStops = MyTab
End Sub

saban
03-11-2008, 12:42 PM
I would like that in textbox which already contains Tab separated text (saban & VbTab & 30 & Vbtab & ....) it is just not aligned like in columns

ex. not like in first text box, but like in seconfd one, and text is already tab separated

fumei
03-12-2008, 12:50 PM
Tinbendr, the OP clearly was asking about a textbox....not the document Range.

Also, why use a variant?

Dim MyTab as TabStop

saban, you are trying to use a textbox for something they are not designed for. First of all, textbox are for INPUT, not displaying text. Labels are for displaying text. A listbox can have columns. Maybe you should try one of those.

Second, you did not answer the question I had regarding the variable. So....

saban
03-12-2008, 02:36 PM
With variable i meant all the text that is inside TextBox because before text is inserted into textbox it is in variable (the whole text)

So you say I can do it with listbox but how???
I tried also but no success??

How can I do it with listbox?

Thnx for all the help

fumei
03-13-2008, 09:54 AM
Look up Listbox in Help. In particular, look up the example of TextColumn Property. As you have the incoming text as a variable - I assume this is ONE variable - then you will have to parse that and split it up.

I will repeat though, a textbox is for user INPUT, not for displaying text. If you are only displaying text, do not use a textbox. If would be very easy to separate your content into three separate labels. After all, if

kjhgkhkhk - is ONE piece of text
saban 360 - is ONE piece of text
Completed - is ONE piece of text

Does it not make sense to have them separate?

saban
03-13-2008, 12:46 PM
I just want them aligned to be more readable not for other purpose

fumei
03-13-2008, 01:18 PM
I give up.

Tinbendr
03-13-2008, 01:45 PM
This is not perfect since the number of spaces in your text fluctuate between 4 and 5.

Sub LinedUpColumnsWithListbox2()
Dim AllText$
Dim MyArray1 As Variant
Dim MyArray2 As Variant
Dim MyText$()
Dim A As Integer
Dim B As Integer
AllText$ = "kjhgkhkhk saban 360 Completed" & vbCr & _
"pol@ghfghfhfghgfhfghmail.com saban 30 Not started" & vbCr & _
"saban 105 Not started"

MyArray1 = Split(AllText$, vbCr)
ReDim MyText$(UBound(MyArray1), 3)
Load UserForm1
'You can specify column widths. Look at Help
UserForm1.ListBox1.ColumnCount = -1
For A = 0 To UBound(MyText)
MyArray2 = Split(MyArray1(A), " ")
For B = 0 To 3
MyText$(A, B) = MyArray2(B)
Next B
Next A
'Assign array to listbox
UserForm1.ListBox1.List = MyText
UserForm1.Show
End Sub

Here's another version that seperates at the first space.
Sub LinedUpColumnsWithListbox3()
Dim MyText$()
Dim AllText$
Dim MyArray As Variant
Dim Offset As Integer
Dim A As Long

'I have to simulate this.
AllText$ = "kjhgkhkhk saban 360 Completed" & vbCr & _
"pol@ghfghfhfghgfhfghmail.com saban 30 Not started" & vbCr & _
"saban 105 Not started"

MyArray = Split(AllText$, vbCr)
ReDim MyText$(UBound(MyArray), 1)
'You could move this to the Initialize event of the userform
Load UserForm1
'You can specify column widths. Look at VBA Help
UserForm1.ListBox1.ColumnCount = -1
For A = 0 To UBound(MyArray)
Offset = InStr(MyArray(A), " ")
MyText$(A, 0) = Left(MyArray(A), Offset)
MyText$(A, 1) = Right(MyArray(A), Len(MyArray(A)) - Offset)
Next A
'Assign array to listbox
UserForm1.ListBox1.List = MyText$
UserForm1.Show
End Sub

fumei
03-14-2008, 01:45 AM
Good grief.

fumei
03-14-2008, 12:06 PM
labels

saban
03-15-2008, 05:17 PM
thnx guys i will look into this

fumei : what is this attachment of yours it is only empty document with password protected macros??

fumei
03-16-2008, 07:55 PM
Did you open it and click the Show Me button on the userform? That is all it is for, to show labels aligned exactly as you want the text to be aligned.

The userform should display on Document_Open. I just downloaded the ZIP file I posted here, unzipped it, and opened the file. It works exactly as I intended it to work.

saban
03-18-2008, 02:32 PM
I cannot access form it is password protected I canot run th eproject

lucas
03-18-2008, 03:29 PM
Gerry tried to help you with this in post #5

Maybe you can take it from here.......

saban
03-18-2008, 04:36 PM
and what should i do with this piece of code that is inside


Private Sub UserForm_Initialize()
Label1.Visible = False
Label2.Visible = False
End Sub
Private Sub CommandButton1_Click()
Label1.Visible = True
Label2.Visible = True
End Sub


I cannot see any conection to what I need ???

lucas
03-18-2008, 04:47 PM
I don't see how you can expect more help than has been offered until you answer the questions posed in post #2

post your code or your document or both and a little more explaination as to what you are trying to do.......

fumei
03-19-2008, 10:30 AM
"I cannot access form it is password protected I canot run th eproject"

As I have already mentioned, and I have tested by downloading the file from this site, the userform should display on opening the document. I don't WANT you to run the project. I want you to look at the userform and SEE something. Why not just do that? Is there a problem with just doing that? As i wrote previously:

"The userform should display on Document_Open. I just downloaded the ZIP file I posted here, unzipped it, and opened the file. It works exactly as I intended it to work."

Did you, or did you not, just open the document as I said to do?

Never mind. Not that I would expect any answer, but I just do not care any more. I am no longer going to respond, this is just too annoying.

saban
03-19-2008, 12:03 PM
sorry I realized that I have macros disabled, enabled it and it worked

Alphacsulb
03-20-2008, 02:47 PM
You have to enable macros for this to work.

mdmackillop
03-21-2008, 09:04 AM
...and if you want your labels to look like textboxes, just format them to suit.

Greg
03-26-2008, 10:02 PM
Hi Tinbendr,

For some time now I have wanted to create separate paragraphs for text entered via a textbox. As a workaround I have simply created separate textboxes for each paragraph.

My solution is ok so long as the number of paragraphs is pre-determined (usually 2 or 3) because I can set up separate documents and userforms for each.

However, if I want a larger number of paragraphs in my document, I have no way of separating them via a single textbox.

Having seen your solution to Saban's question I am curious to know if paragraphs, preferably numbered with an indent after the number, can be achieved in a manner similar to that described at item 10 above.

If this question should be a separate Post please say so.

Regards,

Greg.

Tinbendr
03-27-2008, 06:57 AM
For some time now I have wanted to create separate paragraphs for text entered via a textbox.It's all about text manipulation before the text gets to the textbox.

See attached.

Greg
03-27-2008, 07:03 PM
Thanks Tinbendr but I'm not sure how to incorporate your example into my document and userform.

The intention, if possible, is to delineate the paragraphs in the textbox so that they are reproduced as separate numbered paragraphs in the document. Delineation via the textbox is the main problem.

For example, if I type a paragraph of text into my userform and then press shift+enter to move the curser down to type the next paragraph, it all looks fine and dandy but when I press OK the bookmark into which that text is inserted "jumps" out of its cell and creates havoc with the cells in other parts of the document.

This is difficult to explain so I suggest that you try it yourself on the attached document. This document already has three separate paragraphs set out in it but I would prefer to create those paragraphs via the userform and not on the document itself.

Do you have any ideas about how this can be achieved?

Regards,

Greg.

fumei
03-29-2008, 10:47 PM
"if I type a paragraph of text into my userform and then press shift+enter to move the curser down to type the next paragraph, it all looks fine and dandy but when I press OK the bookmark into which that text is inserted "jumps" out of its cell and creates havoc with the cells in other parts of the document."

Greg, you are inserting the contents of the textbox as ONE string into ONE bookmark.

You do not explain yourself well. You force us to figure out what you are asking. In this case, it is the Indorsement, and the three paragraphs in your document with it. the bookmark (Indorsement) does NOT cover the three sentences, just the first.

"Do you have any ideas about how this can be achieved?"

As i mention to you before, it helps if you clearly state what you mean. How WHAT can be achieved?

Could you create those paragraphs via the userform? Yes, of course you can.

Greg
03-30-2008, 01:47 AM
Hi Gerry,

Yes, upon reflection I could have explained myself far better.

My problem is not new and we have both expored this once before. Put simply I want to know if there is way to created separate numbered paragraphs via a single textbox in a Userform.

In the document provided above there is a bookmark named "indorsement" into which I am able to enter text for one paragraph. To enter text for more than one paragraph I have to use a different document. A sample containing 3 paragraphs is attached.

My solution is clumsy and inflexible and I would much prefer to create separate paragraphs in one bookmark if it were possible.

Gerry, this is as clear as I can be.

Regards,

Greg.

mdmackillop
03-30-2008, 04:22 AM
As in this?

Tinbendr
03-30-2008, 05:56 AM
Greg,
Check your private messages.

Greg
03-31-2008, 12:50 AM
Sorry,

I can't open that file.

Greg
03-31-2008, 02:56 AM
Actually,

I have managed to open and save that file but I still have the same old problem that I used to have. That is, if I put your bookmark into the cell above it and then press Ctrl+Enter to create a new paragraph, the bookmark relocates itself outside the cell. Once the bookmark goes into the cell, it behaves quite unexpectedly by trying to get out again.

fumei
03-31-2008, 10:15 AM
I see no problem except for....

you are not using Styles!!!!.

" if paragraphs, preferably numbered with an indent after the number, can be achieved in a manner similar to that described at item 10 above."

Yes. Use proper styles. If the style is numbered, and you put in ONE string from the textbox, and that string has paragraph marks, then the string will...have paragraph mark. So each paragraph will take on the format of the style...which is.....numbered.

Like this - in the demo attached. The three separate paragraphs - or four...or six..or 14...or how many you like - will still go into one bookmark...but, ummm, are numbered.

The fact that you are not using Styles at all is a serious mistake. But then, you know that already.

If your particular issue is to be continued, perhaps it would be best for it to have its own thread.

mdmackillop
03-31-2008, 10:42 AM
Hi Gerry,
I came up with the basically same solution, reposted in #28.

Jake has kindly upped the attachment size to 1Mb so no more zipping!

fumei
03-31-2008, 11:00 AM
Ooops. Sorry. I missed that. Bad dog.

Although I now have taken a look, and yes, it is essentially identical...except for you do not Unload the userform with the commandbutton. I kept on clicking the commandbutton, and clicking, and clicking...until..hmmmm, I better click the "x".

Bad dog.