Click here to Skip to main content
12,950,268 members (63,267 online)
Rate this:
Please Sign up or sign in to vote.
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
       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
        'Colum Resize
        'Hide Borders
        Hideborders wordTable
    wordDoc.SaveAs "C:\Sample.doc"
    wordDoc.Close True
    wordApp.Quit True
    Set wordDoc = Nothing
    Set wordApp = Nothing
End Sub

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

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.[^]

Good luck!

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 5,829
CHill60 3,460
Maciej Los 2,953
Jochen Arndt 1,975
ppolymorphe 1,820

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 4 Jul 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100