By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,480 Members | 771 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,480 IT Pros & Developers. It's quick & easy.

remove table border in word from vb

100+
P: 138
plz urgent help needed
i have one data grid in the form. i have to export the data from the datagrid to the word.
i just exported the data in MS word into a table. but i want to remove the table border. but i am not able to do so till now
can any one help me in this matter
i am using vb6.
TIA
May 3 '07 #1
Share this Question
Share on Google+
12 Replies


SammyB
Expert 100+
P: 807
plz urgent help needed
i have one data grid in the form. i have to export the data from the datagrid to the word.
i just exported the data in MS word into a table. but i want to remove the table border. but i am not able to do so till now
can any one help me in this matter
i am using vb6.
TIA
After Word appears, record a maco that deletes the border, then look at the code and it will show you what objects to use. Your code will be something like
Expand|Select|Wrap|Line Numbers
  1.     oDocument.Tables(1) .Borders(wdBorderTop).LineStyle = wdLineStyleNone
  2.     oDocument.Tables(1) .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
  3.     oDocument.Tables(1) .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
  4.     oDocument.Tables(1) .Borders(wdBorderRight).LineStyle = wdLineStyleNone
  5.     oDocument.Tables(1) .Borders(wdBorderHorizontal).LineStyle = wdLineStyleNone
  6.     oDocument.Tables(1) .Borders(wdBorderVertical).LineStyle = wdLineStyleNone
  7.     oDocument.Tables(1) .Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
  8.     oDocument.Tables(1) .Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
May 3 '07 #2

100+
P: 138
thanx for the suggestion
but it does not work
it doesnot remove the border. it still appears in the table.
i want complete removal of the border
thanx
May 4 '07 #3

SammyB
Expert 100+
P: 807
thanx for the suggestion
but it does not work
it doesnot remove the border. it still appears in the table.
i want complete removal of the border
thanx
What does your macro do differently to remove the border? or What do you have to do manually to remove the border? and/or Does my code do anything?
May 4 '07 #4

100+
P: 138
thanx again Sam
it just worked in the print preview. it's okay for now, but now i have another problem, how can i format the text in each column in the table. i want the font size, font and the alignment changed in each column.
can u or anyone suggest for this problem??????

best regards
coolminded
May 8 '07 #5

100+
P: 138
thanx again Sam
it just worked in the print preview. it's okay for now, but now i have another problem, how can i format the text in each column in the table. i want the font size, font and the alignment changed in each column.
can u or anyone suggest me for this problem??????

best regards
coolminded
May 8 '07 #6

SammyB
Expert 100+
P: 807
thanx again Sam
it just worked in the print preview. it's okay for now, but now i have another problem, how can i format the text in each column in the table. i want the font size, font and the alignment changed in each column.
can u or anyone suggest me for this problem??????

best regards
coolminded
Use oDoc.Table(1).Cell(1,1).Range and you will find Font.Size, Font.Size, ParagraphFormat, etc. You will have to iterate thru all of the cells. There is a Columns property, but no Range object under that. In Word, everything revolves around the Range object.
May 8 '07 #7

100+
P: 138
sorry to bother u again but the code u provided did not work. coz the cells(1,1) is not allowed and neither other properties like bold, and all other things is allowed, plz help.

following is my code i used to show all the items one by one in each line in word without the border of the table.

plz have a look and plz suggest what should i do to have so, with all the items centered aligned and the size of the font is different for each items with different font name.

Expand|Select|Wrap|Line Numbers
  1. Private Sub command2_click()
  2. Dim oWord As Word.Application
  3. Dim oDoc As Word.Document
  4.  
  5. Dim i As Integer
  6. Dim X
  7. Dim w As Integer
  8.     Set oWord = New Word.Application
  9.     Set oDoc = New Word.Document
  10.  
  11.     oDoc.ActiveWindow.Selection.Tables.Add Range:=oDoc.ActiveWindow.Selection.Range, numrows:=1, numcolumns:=1
  12.     oDoc.ActiveWindow.Selection.FormattedText.AutoFormat
  13.     oDoc.Tables(1).Borders(wdBorderLeft).Visible = False
  14.     oDoc.Tables(1).Borders(wdBorderTop).Visible = False
  15.     oDoc.Tables(1).Borders(wdBorderBottom).Visible = False
  16.     oDoc.Tables(1).Borders(wdBorderRight).Visible = False
  17.     oDoc.Tables(1).Borders(wdBorderHorizontal).Visible = False
  18.     oDoc.Tables(1).Borders(wdBorderDiagonalUp).Visible = False
  19.     oDoc.Tables(1).Borders(wdBorderVertical).Visible = False
  20.     oDoc.Tables(1).Borders(wdBorderDiagonalDown).Visible = False
  21.        i = 0
  22.        w = 0
  23.        For i = 1 To fg.Rows - 1
  24.  
  25.           If w = 0 Then
  26.             w = w + 1
  27.             oDoc.Tables(1).Columns(1).Cells(w).Range.Text = fg.TextMatrix(i, 0)
  28.  
  29.           Else
  30.             w = w + 1
  31.             oDoc.Tables(1).Columns(1).Cells.Add
  32.             oDoc.Tables(1).Columns(1).Width = 500
  33.             oDoc.Tables(1).Columns(1).Cells(w).Range.Text = fg.TextMatrix(i, 0)
  34.           End If
  35.  
  36.           w = w + 1
  37.           oDoc.Tables(1).Columns(1).Cells.Add
  38.           oDoc.Tables(1).Columns(1).Width = 500
  39.           oDoc.Tables(1).Columns(1).Cells(w).Range.InlineShapes.AddPicture FileName:=fg.TextMatrix(i, 3), _
  40.           SaveWithDocument:=True
  41.  
  42.           w = w + 1
  43.           oDoc.Tables(1).Columns(1).Cells.Add
  44.           oDoc.Tables(1).Columns(1).Width = 500
  45.           oDoc.Tables(1).Columns(1).Cells(w).Range.Text = fg.TextMatrix(i, 1)
  46.  
  47.           w = w + 1
  48.           oDoc.Tables(1).Columns(1).Cells.Add
  49.           oDoc.Tables(1).Columns(1).Width = 500
  50.           oDoc.Tables(1).Columns(1).Cells(w).Range.Text = fg.TextMatrix(i, 2)
  51.             Next i
  52.         Unload FrmBar1
  53.     oDoc.ActiveWindow.Document.Close True
  54.     Set oDoc = Nothing
  55.     oWord.Quit False
  56.     Set oWord = Nothing
  57.     Set Db = Nothing
  58. End Sub
again thanx in advance.
May 8 '07 #8

SammyB
Expert 100+
P: 807
>coz the cells(1,1) is not allowed
try cell(1,1) without the s
like I posted :)

BTW, You can use .Columns(i).Cells(iRow).Font.Name = "Arial"
this time you use Cells with the s
but your code is strange, don't you want Columns(i) instead of Columns(1)?
May 8 '07 #9

100+
P: 138
>coz the cells(1,1) is not allowed
try cell(1,1) without the s
like I posted :)

BTW, You can use .Columns(i).Cells(iRow).Font.Name = "Arial"
this time you use Cells with the s
but your code is strange, don't you want Columns(i) instead of Columns(1)?
once again thanx
why i use columns(1) instead of columns(i) because i want all the items displayed in a single column. i want to show it as it is displayed in the different line of the word document. but not in a matrix format.

it worked perfectly, i can use the different font name, with different font size,
but now i want to change its alignment. i.e. either left, or right, or center or justified. it doesn't show the alignment property. how can i set the property to center alignment, or right alignment and so on.

can you help me in this matter.
TIA
May 9 '07 #10

100+
P: 138
thank you sam
but i found it to make the alignment center
just i have to go to the property of paragraph, i.e.
odoc.tables(1).columns(1).cells(w).range.paragraph s.alignment=wdalignparagraphcenter
once agaain thanx a lot for helping me in this.
bye
May 9 '07 #11

100+
P: 138
thank you sam
but i found it to make the alignment center
just i have to go to the property of paragraph, i.e.
odoc.tables(1).columns(1).cells(w).range.paragraph s.alignment=wdalignparagraphcenter
once agaain thanx a lot for helping me in this.
bye

once again i am bothering you
i finished my work but one problem arises when the size of the pic is large it comes in the next page and if the size of the pic is small, content of next item comes in the same page. how can i format the size of the pic so that it remains to the same size either it is small or large, can it be done.
thanx
May 9 '07 #12

SammyB
Expert 100+
P: 807
Before you add the picture, setup the table so that it will not auto-scale. Something like this:
Expand|Select|Wrap|Line Numbers
  1.     ActiveDocument.Tables(1) .Rows.HeightRule = wdRowHeightExactly
  2.     ActiveDocument.Tables(1) .Rows.Height = CentimetersToPoints(5)
  3.     ActiveDocument.Tables(1) .Columns.PreferredWidthType = wdPreferredWidthPoints
  4.     ActiveDocument.Tables(1) .Columns.PreferredWidth = CentimetersToPoints(4)
  5.     ActiveDocument.Tables(1) .AutoFitBehavior wdAutoFitFixed
  6.     ActiveDocument.Tables(1) .Cell(2, 1).Range.InlineShapes.AddPicture FileName:= _
  7.         "C:\Documents and Settings\Sam\My Documents\My Pictures\CoffsHarbour.jpg", _
  8.         LinkToFile:=False, SaveWithDocument:=True
BTW, I know next to nothing about Word. I just recorded several macros of playing with the Table properties, then used Intellisense until I had something that worked. You too can be an "expert" ! ;) Sam
May 10 '07 #13

Post your reply

Sign in to post your reply or Sign up for a free account.