Results 1 to 11 of 11

Thread: **RESOLVED** Need Help With Adding Multiple Tables Into Word From Vb??

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Location
    New York
    Posts
    679

    **RESOLVED** Need Help With Adding Multiple Tables Into Word From Vb??

    I need to know how I can write the code for multiple tables into Word...

    The code I have is as follows:
    VB Code:
    1. On Error GoTo Error_Handler
    2.        
    3.  Dim intNumofRows As Integer
    4.  Dim intNumofColumns As Integer
    5.  Dim p As Integer, ColWidth As Integer
    6.  Dim i As Integer
    7.  
    8.  
    9.  
    10.     intNumofColumns = m_Recordset.Fields.Count
    11.     intNumofRows = m_Recordset.RecordCount
    12.  
    13.     'Insert a new table with rows according to recordCount plus Column header
    14.     'and the number of columns in the recordset
    15.    
    16.    
    17.      
    18.     wrdDoc.Tables.Add wrdSelection.Range, NumRows:=intNumofRows + 1, _
    19.     NumColumns:=intNumofColumns
    20.    
    21.     iTableCounter = iTableCounter + 1
    22.    
    23.    
    24.    
    25.     With wrdDoc.Tables(iTableCounter)
    26.     ' Set the column widths
    27.      For i = 0 To intNumofColumns - 1
    28.      ColWidth = Len(m_Recordset.Fields(i).Name)
    29.         .Columns(i + 1).SetWidth ColWidth * 25, wdAdjustNone
    30.         .Cell(1, i + 1).Range.InsertAfter UCase(m_Recordset.Fields(i).Name)
    31.      Next i
    32.        
    33.         ' Set the shading on the first row to light gray
    34.         .Rows(1).Cells.Shading.BackgroundPatternColorIndex = wdGray25
    35.        
    36.         ' Bold the first row
    37.         .Rows(1).Range.Bold = True
    38.        
    39.         ' Center the text in Cell (1,1)
    40.         .Cell(1, 1).Range.Paragraphs.Alignment = wdAlignParagraphCenter
    41.        
    42.         ' Fill each row of the table with data
    43.         For i = 1 To intNumofRows
    44.          For p = 1 To intNumofColumns
    45.           FillRow i + 1, p, m_Recordset.Fields(p - 1)
    46.          Next p
    47.          p = 1
    48.          m_Recordset.MoveNext
    49.         Next i
    50.     End With
    51.        
    52.    Set m_Recordset = Nothing
    53.    
    54.    
    55.    
    56.    
    57.   Exit Sub
    58.    
    59. Error_Handler:
    60.          
    61.     Debug.Print Err.Description & " - " & Err.Number
    This routine will be used to insert tables...the problem is that the liine of code ' wrdDoc.Tables.Add wrdSelection.Range' is being used more than once...When the 2nd table is being sent to the Word object the Debug.Print is saying that there is all ready a table in that location...

    I need to find the code to have multiple table on the same document????

    Thanks
    Last edited by Salvatore; Apr 26th, 2004 at 04:01 PM.

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