[RESOLVED] How to add lines and tab spaces to a Word doc
Hello all
I have a Word 2003 userform. The options selected within the userform are used to build a quotation by adding text to bookmarks within the document.
I now want to add a "features list" to the document, which can vary in length depending on what is being quoted, e.g. it could contain 5 items or it could contain 10 items. The Word list is something like this:
Item 1: Details for item 1
Item 2: Details for item 2
Item 3: Details for item 3
and so on...
Items 1-3 are universal and so are in the document already as standard text. What I am trying to find out is a means to add the extra lines necessary, but also apply the same tab spaces between "Item n:" and "Details for item n".
At the moment, I have a bookmark at the end of the line containing item 3. If it is necessary to add another item I simply use vbCr to move to the next line, but I don't know how to add the tab.
Adding the extra lne using the above method is also possibly not the best method because I create strings depending on choices made. Some of the strings may be blank. I then simply use:
VB Code:
.Bookmarks("Features").Range.Text = vbCr & strItem4 & vbCr & strItem5 & vbCr & strItem6 etc
But I don't know how to disregard blank strings to avoid adding extra lines.
Any help would be greatly appreciated. :)
Re: How to add lines and tab spaces to a Word doc
Sounds like you should be placing the data in a table. That will help with the Tabs as columns and identifing rows or cells for adding data.
Re: How to add lines and tab spaces to a Word doc
Quote:
Originally Posted by RobDog888
Sounds like you should be placing the data in a table. That will help with the Tabs as columns and identifing rows or cells for adding data.
Thanks RobDog. I did consider using tables, but I have not used them before in conjunction with vba.
How do I add a row and how are cells identified?
Thanks again :)
Re: How to add lines and tab spaces to a Word doc
I take it you want to add them programmatically.
VB Code:
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=2, NumColumns:=5, _
DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed
Re: How to add lines and tab spaces to a Word doc
Thanks RobDog. I used the the code you kindly supplied to investigate further and found "InsertRowsBelow" which is perfect for what I am doing.
Much appreciated. :)