#1
|
|||
|
|||
How to run a macro on only specific tables in a mail merge export
Hello, a newbie here with almost zero VBA experience.
We have a mail merge template with a macro that does the following: Step 1: generates the mail merge for all records in the data spreadsheet (creating a huge word document) Step 2: deletes blank rows off the table(s). Step 3: creates a separate PDF for each record (so we don't have one giant mail merged document but one for each person). It works brilliantly on the mail merge template that has just one table. Now I have a mail merge template that has 3 tables: - Table 1: 5x5 - Table 2: 26 columns x 19 rows - Table 3: 2x2 I want our 'removing blank rows' macro to only run on Table 2. Of course in the huge mail merge document created in Step 2, this is table 2 on the first page, but then will be table 5, table 8, table 11 (basically every 3rd table from table 2). It has the same identical table headings so it would be possible to search for specific text and then have that table selected. The mail merge document has data from about 200 records so it's fairly large (and time-consuming to delete blank rows manually). We're using this macro code to delete the rows (taken from another post on this forum)... Code:
Dim Tbl As Table, i As Long With ActiveDocument For Each Tbl In .Tables With Tbl For i = .Rows.Count To 2 Step -1 If Len(.Cell(i, 3).Range.Text) = 2 And Len(.Cell(i, 9).Range.Text) = 2 Then .Rows(i).Delete Next i End With Next Tbl End With Any help to get my head around this problem would be great and thank you so much in advance. |
#2
|
||||
|
||||
For example:
Code:
Dim s As Long, i As Long With ActiveDocument For s = 1 To .Sections.Count - 1 With Sections(s).Range.Tables(2) For i = .Rows.Count To 2 Step -1 If Len(.Cell(i, 3).Range.Text) = 2 And Len(.Cell(i, 9).Range.Text) = 2 Then .Rows(i).Delete Next i End With Next End With
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Thanks so much, I'll give this a whirl when I'm back at work on Monday.
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to separate mail merge tables | Tesla | Mail Merge | 1 | 05-05-2022 06:55 AM |
Export .csv file to Word for Mail Merge? | Jshopping | Mail Merge | 3 | 09-22-2018 11:04 PM |
Update & Unlink Specific Merge Field in Word Doc from Mail Merge - Excel VBA | RMerckling | Mail Merge | 16 | 05-17-2018 05:19 PM |
how do i ad a specific pdf file to a mail merge? | mseibel | Mail Merge | 1 | 08-28-2012 07:53 PM |
specific mail merge | cmccabe | Mail Merge | 3 | 06-14-2012 04:12 PM |