Select row with checkbox and copy to other doc!

T

TooN

Hello..!

Ive got a document that includes a table with about 500 rows and 7 columns.
From that document i create a second document that is client specific.
Document 1 contains specific data in every row. If i create a client specific
document i select a row and copy it to the second document.

Works good but it drives me crazy. And because other people work with the
same document ass well it is not working out good. I was thinking of getting
an extra column with a checkbox. When i open document 1 i select all the rows
in the table that i want in document 2 (the client specific one) with a
checkbox (every row got his own checkbox) and than push a button that will
copy the selected rows to another word document (or template)

I hope someone can help me with this ...

Thanks
 
D

Doug Robbins - Word MVP

See the article "How to create a Userform" at:

http://word.mvps.org/FAQs/Userforms/CreateAUserForm.htm

See the article "How to find out which Items are selected in a Multi-Select
ListBox" at:

http://www.word.mvps.org/FAQs/Userforms/GetMultiSelectValues.htm

Use a routine such as the following to load a multi-select listbox in the
userform with the data from your table

This routine loads a listbox with client details stored in a table in a
separate
document (which makes it easy to maintain with additions, deletions etc.),
that document being saved as Clients.Doc for the following code.

On the UserForm, have a list box (ListBox1) and a Command Button
(CommandButton1) and use the following code in the UserForm_Initialize() and
the CommandButton1_Click() routines

Private Sub UserForm_Initialize()
Dim sourcedoc As Document, i As Integer, j As Integer, myitem As Range,
m As Long, n As Long
' Modify the path in the following line so that it matches where you
saved Clients.doc
Application.ScreenUpdating = False
' Open the file containing the client details
Set sourcedoc = Documents.Open(FileName:="e:\worddocs\Clients.doc")
' Get the number or clients = number of rows in the table of client
details less one
i = sourcedoc.Tables(1).Rows.Count - 1
' Get the number of columns in the table of client details
j = sourcedoc.Tables(1).Columns.Count
' Set the number of columns in the Listbox to match
' the number of columns in the table of client details
ListBox1.ColumnCount = j
' Define an array to be loaded with the client data
Dim MyArray() As Variant
'Load client data into MyArray
ReDim MyArray(i, j)
For n = 0 To j - 1
For m = 0 To i - 1
Set myitem = sourcedoc.Tables(1).Cell(m + 2, n + 1).Range
myitem.End = myitem.End - 1
MyArray(m, n) = myitem.Text
Next m
Next n
' Load data into ListBox1
ListBox1.List() = MyArray
' Close the file containing the client details
sourcedoc.Close SaveChanges:=wdDoNotSaveChanges
End Sub


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
D

David Sisson

This is sort of what you asked for... (but I would do it Jonathan's
way if it were me.)

Instead of a Checkbox, which would require the document to be
protected, this routine uses a cell in column 1.

So, add a column and place a check (the letter X) in the row you want
to include in the second document.

Sub SelectCheck()
Dim aDoc As Document
Dim aDoc2 As Document

Dim aTable As Table
Dim MyRange As Range
Dim MyCell As Range

Dim NumRows As Integer
Dim A As Integer

Set aDoc = ActiveDocument
Set aTable = aDoc.Tables(1) 'Adjust to your table number
Set aDoc2 = Documents.Add

NumRows = aTable.Rows.Count

For A = 1 To NumRows
With aTable
'Get the contents of the first cell and see if there's a check
Set MyCell = .Cell(A, 1).Range

'Strip off the end of cell marker
MyCell.MoveEnd wdCharacter, -1

'If check found then paste it in the new Doc.
If MyCell = UCase("X") Then
.Rows(A).Range.Copy
Set MyRange = aDoc2.Range _
(Start:=aDoc2.Content.End - 1, _
End:=aDoc2.Content.End - 1)
MyRange.Paste

'Clears the Check
MyCell.Text = ""
End If
End With
Next A

End Sub

Hope this helps.
David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top