Consulting

Results 1 to 13 of 13

Thread: Solved: creating table under Word.application object

  1. #1

    Solved: creating table under Word.application object

    I have the following tabular information to be put in a Word document.

    AAA 111
    BBB 22222222222222
    CCCCCC 33333
    DDDD 444444444444444444444
    EE 123

    Could any one tell me how to do it in VB coding with bold font (no grid lines needed)
    Thanks.

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Try this.

    [VBA] Option Explicit

    Sub AddTable()

    Dim Tbl As Table

    Set Tbl = ActiveDocument.Tables.Add(Range:=Selection.Range, _
    NumRows:=4, NumColumns:=2)
    Tbl.Range.Font.Bold = True
    Tbl.Cell(1, 1).Range.Text = "AAA"
    Tbl.Cell(1, 2).Range.Text = "111"

    End Sub
    [/VBA]

  3. #3
    Thanks.
    A question - if I want the first column to be 20 characters only and the second to be 45 columns. How could I do the settings with the table "Tb1" ?
    A new one challenge is I have the following format

    How are you?
    I have the pleasure of displaying the items as followed -

    AAA 111
    BBB 22222222222222
    CCCCCC 33333
    DDDD 444444444444444444444
    EE 123

    Thank you for visiting!
    Have a good day.

    Could you please tell me how the accomplish the above?
    Thanks again for the help.

  4. #4
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    You could have the first and last text outside of the table. ??

  5. #5
    One of my question is how to set the colum width?
    Thanks.

  6. #6
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    You can use this:
    [vba]
    Tbl.Columns(1).Width = 20
    [/vba]

  7. #7
    Thanks again!
    Last question for the text lines (other than table), how I could put font for them

    eg. How are you?
    I have the pleasure of displaying the items as followed -

    For the above two lines I want to have font (12) and bold face .

    THANKS!

  8. #8
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Try this.

    [vba]
    Selection.Font.Bold = True
    Selection.TypeText Text:="Test"
    [/vba]

  9. #9
    Could ask another one? Greedy ..
    For this ..
    Selection.Font.Bold = True
    Selection.TypeText Text:="Test"
    How to change alignment (like Left/Center/Right)?
    THANKS!

  10. #10
    Administrator
    VP-Knowledge Base VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi,

    Try:[vba]
    Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft[/vba]

    This sort of stuff can easily be recorded with the macro recorder and this will save you time looking for answers.

    Go to Tools/Macro/Record macro. Perform the actions you need and stop the recorder. After that a new module (NewMacros) is created with your recorded code.

    This recorded code is not the neatest in the book but it can sure help you find your way arround Word.

    HTH,
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  11. #11
    A big THANKS to all!

  12. #12
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    You're Welcome

    Take Care

  13. #13
    Administrator
    VP-Knowledge Base VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Glad we could help you!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

Posting Permissions

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