View Full Version : Solved: creating table under Word.application object
Mr Doubtfire
07-18-2005, 06:22 AM
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.:bow:
Jacob Hilderbrand
07-18-2005, 09:14 AM
Try this.
 
 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
Mr Doubtfire
07-18-2005, 09:52 AM
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.
Jacob Hilderbrand
07-18-2005, 10:02 AM
You could have the first and last text outside of the table. ??
Mr Doubtfire
07-18-2005, 10:16 AM
One of my question is how to set the colum width?
Thanks.
Jacob Hilderbrand
07-18-2005, 10:33 AM
You can use this:
Tbl.Columns(1).Width = 20
Mr Doubtfire
07-19-2005, 08:56 AM
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!
Jacob Hilderbrand
07-19-2005, 10:57 AM
Try this.
 
Selection.Font.Bold = True
Selection.TypeText Text:="Test"
Mr Doubtfire
07-19-2005, 02:00 PM
Could ask another one? Greedy ..
For this ..
Selection.Font.Bold = True 
Selection.TypeText Text:="Test" 
How to change alignment (like Left/Center/Right)?
THANKS!
MOS MASTER
07-19-2005, 02:17 PM
Hi, :yes 
 
Try:
Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
 
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, :whistle:
Mr Doubtfire
07-19-2005, 05:59 PM
A big THANKS to all!
Jacob Hilderbrand
07-19-2005, 06:30 PM
You're Welcome :beerchug:
 
Take Care
MOS MASTER
07-20-2005, 01:23 PM
Glad we could help you! :yes
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.