PDA

View Full Version : Solved: Losing indentation when using multiline text box



view
08-25-2009, 07:17 AM
Hello all,

Edit - apologies if the required info is documented somewhere and I haven't searched hard enough - have been looking but not managed to find any thing yet.

Firstly - thank you all who contribute to this site - over recent weeks I've been scouring many articles and discussions on this site finding an invaluable resource of information. 2 weeks ago I'd never written a line of VBA - I now have a very nearly complete UserForm with some quite cool (imo) features :)

However, to the major remaining problem;

The UserForm that is completed on opening the document has a multiline text box.

The input from that text box is inserted at a bookmark towards the end of the document. The text needs to be indented. I added a Chr(9) in and it tabs the first line ok, but the subsequent lines lose the indentation.

Could any one advise how to solve this? (If it makes any difference - the number of lines of text inputted often varies)

Oh, and another quick question - how do I take a string and make it all capital letters?

Any advice/help on these would be greatly appreciated.

Tommy
08-25-2009, 09:25 AM
Oh, and another quick question - how do I take a string and make it all capital letters?



StringVariable = Ucase(StringVariable)


On the other part I am thinking that you need to apply a style to the bookmark.: pray2:

view
08-25-2009, 10:03 AM
Hmm ok - will do some experimenting and see if any thing works. Thanks for the help :)

Oh and also for the capital issue - sorted now thanks

view
08-25-2009, 04:58 PM
Not had much luck with the styling - either I'm missing something, or there's a much cleaner way of doing this :/

lucas
08-26-2009, 11:25 AM
You didn't post your example, that's why people won't take the time to help with this. We hate recreating what you have in front of you. See the problem?

That being said, I took time out of my busy schedule to re-create what you describe, at least I think so.

Take a look and then maybe you can ask more direct questions or provide a true example of what you are trying to accomplish.

view
08-27-2009, 03:14 AM
Thank you for that Lucas.

I looked at it but it appears to have the same problem I'm having - the first line is indented, but subsequent lines are not (i.e. they start at the left margin, rather than a tab space in).

Sorry for not giving more detail/example.

If doc_CC.TextLength > 0 Then .Bookmarks("CCs").Range.Text = vbCr + "CC: " + Chr(9) + doc_CC + vbCr

This is what I'm using so far.

Thanks

Paul_Hossler
08-27-2009, 06:01 AM
I think you need to process the characters in the Textbox string, and insert the tabs as needed


Private Sub CommandButton1_Click()
Dim oBM As Word.Bookmarks
Dim s As String
Dim i As Long

Set oBM = ActiveDocument.Bookmarks
For i = 1 To Len(TextBox1.Value)
If Mid(TextBox1.Value, i, 1) = vbLf Then
If i <> Len(TextBox1.Value) Then
s = s & Mid(TextBox1.Value, i, 1) & vbTab
End If
Else
s = s & Mid(TextBox1.Value, i, 1)
End If
Next i
'Bookmark name is Example 1
oBM("Example1").Range.Text = s
Unload Me
End Sub


Paul

Tinbendr
08-27-2009, 09:37 AM
I think Lucas wanted an Document example, but nevertheless, this seems to work for me.


Private Sub cmdOK_Click()
'Indent however many times you need.
ActiveDocument.Bookmarks("BMInsert").Range.Paragraphs.Indent
ActiveDocument.Bookmarks("BMInsert").Range.Paragraphs.Indent
ActiveDocument.Bookmarks("BMInsert").Range.Text = txtMultiline.Text
End Sub

view
08-28-2009, 03:23 AM
Awesome thanks very much all. :D