Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-17-2014, 12:26 AM
selman555 selman555 is offline Script starts nesting tables without reason Windows 7 64bit Script starts nesting tables without reason Office 2013
Novice
Script starts nesting tables without reason
 
Join Date: Oct 2014
Posts: 2
selman555 is on a distinguished road
Question Script starts nesting tables without reason

I'm debugging an application at the moment where a colleague of mine created a method that iterates through all record sets and turns them into tables in a .docx document.



Something goes horribly wrong when creating a document for a large dataset, though.

Here's the code:

Code:
    With objWord.Selection
    .Find.Execute
    While .Find.Found
        
        'Set the size and font for the entire selection
        .Font.Name = "Calibri"
        .Font.Size = 10
    
        rsPDA.MoveFirst
        While Not rsPDA.EOF

            'Header above a series of tables
            If sLeefdomein <> rsPDA.value("Leefdomein") Then
                sLeefdomein = rsPDA.value("Leefdomein")
                .Font.Size = 12
                .Font.Bold = True
                .TypeText Text:=vbNewLine + sLeefdomein
                .Font.Size = 10
                .Font.Bold = False
            End If
            
            'Create new table
             Set t = objWord.ActiveDocument.Tables.Add(Range:=objWord.Selection.Range, _
                                              NumRows:=5, _
                                              NumColumns:=6, _
                                              DefaultTableBehavior:=wdWord9TableBehavior, _
                                              AutoFitBehavior:=wdAutoFitWindow)
            'Define columns
            t.Cell(1, 2).Merge MergeTo:=t.Cell(1, 6)
            t.Cell(2, 2).Merge MergeTo:=t.Cell(2, 6)
            t.Cell(3, 2).Merge MergeTo:=t.Cell(3, 6)
            t.Cell(4, 2).Merge MergeTo:=t.Cell(4, 6)

            'Insert data
            t.Cell(1, 1).Range.Text = "Probleem": t.Cell(1, 1).Range.Font.Italic = True
            t.Cell(1, 2).Range.Text = rsPDA.value("Probleem")

            t.Cell(2, 1).Range.Text = "Doel": t.Cell(2, 1).Range.Font.Italic = True
            t.Cell(2, 2).Range.Text = rsPDA.value("Doel")

            t.Cell(3, 1).Range.Text = "Actie": t.Cell(3, 1).Range.Font.Italic = True
            t.Cell(3, 2).Range.Text = rsPDA.value("Actie")

            t.Cell(4, 1).Range.Text = "Uitvoering": t.Cell(4, 1).Range.Font.Italic = True
            t.Cell(4, 2).Range.Text = rsPDA.value("Uitvoering")

            t.Cell(5, 1).Range.Text = "Prob. eval. ": t.Cell(5, 1).Range.Font.Italic = True
            t.Cell(5, 2).Range.Text = rsPDA.value("DatumProbleemEvaluatie")
            t.Cell(5, 3).Range.Text = "Actie evaluatie ": t.Cell(5, 3).Range.Font.Italic = True
            t.Cell(5, 4).Range.Text = rsPDA.value("DatumAktieEvaluatie")
            t.Cell(5, 5).Range.Text = "Tijd ": t.Cell(5, 5).Range.Font.Italic = True
            t.Cell(5, 6).Range.Text = rsPDA.value("Tijd")
            Set t = Nothing 'Destroy table reference.

            'Set cursor for next while loop
            .MoveDown Unit:=wdLine, Count:=5
            .TypeText Text:=vbNewLine
        
            Sleep 100 'Even 1000 doesn't change anything.
            
            rsPDA.MoveNext
        Wend

        .Find.Execute
    Wend
The generated document looks like this:



All goes well until page 7 or 8 (no matter what's in the dataset).
I was thinking maybe the WordObjects Tables.Add method is working async behind the scenes and
this code pumps the next table into it's rendering engine too quickly? But I'm not sure because a sleep on 100, 250 and 1000 didn't event change the position where the tables started to nest.

Any help or tips would be appreciated.
Reply With Quote
  #2  
Old 10-17-2014, 01:01 AM
selman555 selman555 is offline Script starts nesting tables without reason Windows 7 64bit Script starts nesting tables without reason Office 2013
Novice
Script starts nesting tables without reason
 
Join Date: Oct 2014
Posts: 2
selman555 is on a distinguished road
Default

Nevermind, got it!
I had to move to the end of the document (.MoveEnd) before moving to a new line.
That fixed it!!!
Reply With Quote
Reply

Tags
tables;formula;automating, vb6



Similar Threads
Thread Thread Starter Forum Replies Last Post
Powerpoint adding '1' to end of text for no reason? LKS PowerPoint 0 05-16-2013 09:40 AM
Script starts nesting tables without reason TOC is right to left for unkown reason Guy Roth Word 12 12-05-2012 08:44 AM
Any possible reason template is not saved upon exiting? New Daddy Word 3 10-17-2012 01:51 PM
Script starts nesting tables without reason Nesting Variables SET, LISTNUM, and REF Wyskers Word 1 11-13-2011 05:43 AM
Word 2003. Is there a reason I can't put images in the footer? cheesysocks Drawing and Graphics 2 02-19-2010 06:16 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:03 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft