![]() |
#1
|
|||
|
|||
![]()
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:
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 |
#2
|
|||
|
|||
![]()
You can test the whole row instead of the individual cells:
Code:
Sub PrintAllTest() Dim oTbl As Table, lngIndex As Long, lngCols As Long, oUndo As UndoRecord Application.ScreenUpdating = False Set oUndo = Application.UndoRecord oUndo.StartCustomRecord ("DeleteRows") With ActiveDocument For Each oTbl In .Tables lngCols = oTbl.Columns.Count For lngIndex = oTbl.Rows.Count To 1 Step -1 If Len(oTbl.Rows(lngIndex).Range) = (2 * lngCols) + 2 Then oTbl.Rows(lngIndex).Delete End If Next lngIndex Next oTbl End With Application.ScreenUpdating = True oUndo.EndCustomRecord MsgBox Dialogs(wdDialogFilePrint).Show ActiveDocument.Undo lbl_Exit: Set oUndo = Nothing Set oTbl = Nothing Exit Sub End Sub |
![]() |
Tags |
delete rows, undo, vba |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
braddgood | Word VBA | 15 | 10-02-2015 01:54 PM |
Find and Delete Rows | damaniam | Word VBA | 1 | 03-11-2014 06:54 AM |
![]() |
dennist77 | Word | 1 | 10-29-2013 11:39 PM |
![]() |
elky1967 | Word VBA | 14 | 09-21-2012 05:27 AM |
![]() |
ubns | Excel Programming | 2 | 08-14-2012 02:01 AM |