Results 1 to 5 of 5

Thread: [RESOLVED] How to add lines and tab spaces to a Word doc

  1. #1

    Thread Starter
    Lively Member New2vba's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    95

    Resolved [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:
    1. .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.
    "Those things we must learn to do, we must learn by doing" (or hope somebody else will take pity and help out )

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Lively Member New2vba's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    95

    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
    "Those things we must learn to do, we must learn by doing" (or hope somebody else will take pity and help out )

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to add lines and tab spaces to a Word doc

    I take it you want to add them programmatically.
    VB Code:
    1. ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=2, NumColumns:=5, _
    2. DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Lively Member New2vba's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    95

    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.
    "Those things we must learn to do, we must learn by doing" (or hope somebody else will take pity and help out )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width