Click here to Skip to main content
12,079,391 members (28,015 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB6 Word
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 4-Jul-11 4:43am
jdandes436
Edited 4-Jul-11 7:45am
thatraja247.5K
v2

1 solution

Rate this: bad
 
good
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.

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

Good luck!
  Permalink  

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


Advertise | Privacy | Mobile
Web04 | 2.8.160212.1 | Last Updated 4 Jul 2011
Copyright © CodeProject, 1999-2016
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