Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I'm creating a project that will write in word document, i want to add layout, i create a table with 2 columns & 1 rows. Now my problem is, how can i create another table in inside the cell of my first table.

Anybody can help please regarding this problem???

here is my code:

Public Sub WriteFO(RecordHandler As ADODB.Recordset, wdPath As String)
    
    If Dir(wdPath, vbDirectory) <> "" Then
        'ctr = CountExcelRows(ExcelPath) + 1
    Else
       FileCopy App.Path & "\tmp\Temp.doc", wdPath
    End If
    
    Dim ImageFilename As Variant

    'Word Declaration
    Dim wordApp As Word.Application
    Dim wordDoc As Word.Document
    Dim wordDoc1 As Word.Document
    'Initialize Word
    Set wordApp = New Word.Application 'CreateObject("Word.Application")
    Set wordDoc = wordApp.Documents.Open(wdPath, , True)
    
    Do While Not (RecordHandler.EOF)
        'Download Images
        ImageFilename = Split(RecordHandler.Fields("ILink"), "/")
        DownloadURL RecordHandler.Fields("ILink"), My & "\rsc\" & ImageFilename(UBound(ImageFilename))
        
        'Insert Details
        Dim wordTable As Word.Table
        Dim wordTable1 As Word.Table
        Set wordTable = wordDoc.Tables.Add(wordDoc.Bookmarks.Item("\endofdoc").Range, 1, 2)
        Set wordTable1 = wordTable.Tables.Add(wordDoc.Tables, 2, 1)
        wordTable.Range.ParagraphFormat.SpaceAfter = 6
        
        wordTable.Cell(1, 1).Range.InlineShapes.AddPicture My & "\rsc\" & ImageFilename(UBound(ImageFilename)), False, True, wordTable.Range
        'wordTable.Cell(1, 2).Range.Text = RecordHandler.Fields("ILink")
        wordTable.Cell(1, 2).Range.Tables.Add wordTable1.Range, 2, 1
        'wordTable.Cell(1, 2).Range.Tables.Add wordTable1.Range, 3, 1
        
        'Insert New Table
        Dim wordPar2 As Word.Paragraph
        Set wordPar2 = wordDoc.Content.Paragraphs.Add
        wordPar2.Range.Text = vbNewLine
        'wordPar2.Range.Font.Italic = True
        wordPar2.Range.InsertParagraphAfter
        
        'Colum Resize
        wordTable.Columns.Item(1).AutoFit
        wordTable.Columns.Item(2).AutoFit
        'Hide Borders
        Hideborders wordTable
        RecordHandler.MoveNext
    Loop
    
    wordDoc.SaveAs "C:\Sample.doc"
    wordDoc.Close True
    wordApp.Quit True
    
    Set wordDoc = Nothing
    Set wordApp = Nothing
End Sub


any idea appreciated!!!
Posted
Updated 4-Jul-11 6:45am
v2

1 solution

It is way easier to simply create a string of all the values and insert them all at once. This is much faster. You separate each value using a tab char (vbTab) and each line with a new line (vbNewLine). Then insert that string as a new bookmark, select that and convert it to a table using ConvertToTable.

http://msdn.microsoft.com/en-us/library/aa171893%28v=office.11%29.aspx[^]

Good luck!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900