Click here to Skip to main content
Rate this: bad
good
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 3:43am
jdandes436
Edited 4-Jul-11 6:45am
thatraja238.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
0 Nirav Prabtani 268
1 OriginalGriff 217
2 Mika Wendelius 185
3 CPallini 170
4 _Amy 170
0 Nirav Prabtani 284
1 OriginalGriff 217
2 Mika Wendelius 185
3 _Amy 170
4 Sergey Alexandrovich Kryukov 154


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