Hey Guys,
at the moment i am doing some new stuff here in my office. At the moment i have to do a Serial/form Letter for an document with a little inventory of all our personals equipment. Since all people have diffrent amount of equipment and accesories i needed to do like an dynamic Table with many combined fields. Like "Model_1" - "Brand_1" .. same for second item and so on.
When i print it later, i dont want to have like 15 empty rows. So i decided to do something about it with VBA. I have now a script - but since im kinda new to this stuff im not sure if this code is well done or if i could do better/faster or something like that.
My Code:
Quote:
Sub PrintAllTest()
Application.ScreenUpdating = False
Dim Tbl As Table, cel As Cell, i As Long, n As Long, fEmpty As Boolean, objUndo As UndoRecord
Set objUndo = Application.UndoRecord
objUndo.StartCustomRecord ("DeleteRows")
With ActiveDocument
For Each Tbl In .Tables
n = Tbl.Columns.Count
For i = n To 1 Step -1
fEmpty = True
For Each cel In Tbl.Columns(i).Cells
If Len(cel.Range.Text) > 2 Then
fEmpty = False
Exit For
End If
Next cel
If fEmpty = True Then Tbl.Columns(i).Delete
Next i
Next Tbl
End With
With ActiveDocument
For Each Tbl In .Tables
n = Tbl.Rows.Count
For i = n To 1 Step -1
fEmpty = True
For Each cel In Tbl.Rows(i).Cells
If Len(cel.Range.Text) > 2 Then
fEmpty = False
Exit For
End If
Next cel
If fEmpty = True Then Tbl.Rows(i).Delete
Next i
Next Tbl
End With
Set cel = Nothing: Set Tbl = Nothing
Application.ScreenUpdating = True
objUndo.EndCustomRecord
Dialogs(wdDialogFilePrint).Show
ActiveDocument.Undo
End Sub
|
So is this code okay for what i wanting to do? Or is there a more easy way to do like i want to? I made this code from diffrent pages and edited.
Again what i need since i guess tis not clear:
1. Delete all empty Rows
2. Print this page
3. Undo all changes (its a form letter so that i dont need one document per user)
Thats it, please advice me if i can do better. I really tried my best so if theres a more easy way - now is the time to help me
Thanks in advance