Variable Printing

M

Michael H

Hi,

Trying to creat a Word Document that contains a Table that a single user
would enter data into through out the day.

The table would/could vary in lenght depending on how busy the user was.

At the end of the day, I'm trying to create some code that the user would
run that would print the table and then print each complete row onto a
seperate sheet of A4, but would then stop at the end of the data.

Cheers
 
G

Greg Maxey

Michael,

Something like this should process the table and print. You would need to
create a template laid out with theappropriate paper size and tab locations.

Sub ScratchMacro()
Dim oTbl As Word.Table
Dim oRow As Word.Row
Dim oCell As Word.Cell
Dim pStr As String
Dim oDoc As Word.Document
Set oTbl = ActiveDocument.Tables(1)
Set oDoc = Documents.Add ' (Point to your template)
For Each oRow In oTbl.Rows
If Not (Len(oRow.Range.Text) / 2) - 1 = oRow.Cells.Count Then
pStr = ""
For Each oCell In oRow.Cells
pStr = pStr & Left(oCell.Range.Text, Len(oCell.Range.Text) - 2) &
vbTab
Next oCell
pStr = Left(pStr, Len(pStr) - 1) & vbCr
oDoc.Range.InsertAfter pStr
End If
Next
AcitveDocument.PrintOut
oDoc.Printout
End Sub
 

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