Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Other Office > Word VBA
|
Word VBA Discuss using VBA to program Word.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Word VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 15th, 2011, 01:21 PM
Authorized User
 
Join Date: Jun 2011
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default insert listbox items into word table rows

Hello everyone,
Please I need help with some codes on populating word tables with data inside a listbox. The listbox has 3 columns, and I will like to add all data in the listbox into word table rows, without actually clicking any data row in the listbox. For example, I want the first row in the listbox to be the first row in the word table and so on.
the code that I thought was going to work only writes the last inserted data in the listbox into the word table after i click the add button. Is it possible for me to write all the data in the listbox into different rows of word table at the same time withouht actually multi-selecting the values?

here is the code:

Dim i As Integer
Dim j As Integer
Dim k As Integer
i = ActiveDocument.Tables(12).Rows.Count - 1
With ActiveDocument.Tables(12)
For j = 0 To lstDescription.ListCount - 1
For k = 0 To lstDescription.ColumnCount
.Rows.Add
With .Rows(i + 1)
.Cells(1).Range.Text = lstDescription.List(j, 1)
.Cells(2).Range.Text = lstDescription.List(j, 1)
.Cells(3).Range.Text = lstDescription.List(j, 0)
End With
Next
Next
End With

I appreciate your kind help!

thanks,

bitex
 
Old July 16th, 2011, 12:07 PM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Here is a hint

Code:
Dim i As Integer
Dim j As Integer
Dim k As Integer
i = ActiveDocument.Tables(12).Rows.Count - 1
With ActiveDocument.Tables(12)
    For j = 0 To lstDescription.ListCount - 1
        For k = 0 To lstDescription.ColumnCount
        .Rows.Add
        .Cell(j + 1, 1).Range.Text = lstDescription.List(j, 0)
        .Cell(j + 1, 2).Range.Text = lstDescription.List(j, 1)
        .Cell(j + 1, 3).Range.Text = lstDescription.List(j, 2)
        Next
    Next
End With
Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Search for listbox item in word table and delete the rows bitex Word VBA 4 July 11th, 2011 09:42 AM
moving items from one listbox to another listbox Nishapd ASP.NET 3.5 Basics 2 December 3rd, 2009 07:20 AM
INSERT multiple rows to a table nvillare Oracle 7 November 3rd, 2007 04:47 AM
Trigger to insert rows in Remote table anirbanbasuz SQL Language 1 August 25th, 2006 06:02 AM
insert rows into the same table nik SQL Server 2000 1 October 26th, 2005 07:28 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.