Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-28-2015, 03:39 AM
eibst eibst is offline automate macro for merged document (after merge) Windows 7 64bit automate macro for merged document (after merge) Office 2010 64bit
Novice
automate macro for merged document (after merge)
 
Join Date: Apr 2015
Posts: 1
eibst is on a distinguished road
Default automate macro for merged document (after merge)

Hi Community!



I got a problem. I'm printing a document from our companies crm with mailmerge. Now the problem is that objects have different attributes (different size) and so sometimes the table gehts filled nearly entirely sometimes its nearly empty ! So I looked for a makro to clean the table and found one working for me :

Code:
  Dim myTable As Table
Dim myRow As Row
Dim myCell As Cell
Dim myRange As Range
Dim IsEmpty As Boolean

For Each myTable In ActiveDocument.Tables
For Each myRow In myTable.Rows
IsEmpty = True
For Each myCell In myRow.Cells
Set myRange = myCell.Range
myRange.MoveEnd Unit:=wdCharacter, Count:=-1
If myRange.Text <> "" Then IsEmpty = False
Next myCell
If IsEmpty Then myRow.Delete
Next myRow
Next myTable
The thing is I want it to run automatically on the merged document which does unfortunately not work with autoOpen(), AutoExec() and so on.
Is there any possibilty that it automatically will be executed on the merged document!

I'm looking forward to your answers

regards
Stefan

PS: Sorry for my bad english
Reply With Quote
  #2  
Old 06-05-2015, 11:36 PM
macropod's Avatar
macropod macropod is offline automate macro for merged document (after merge) Windows 7 64bit automate macro for merged document (after merge) Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,471
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

If your mailmerge is being run through code, you could use that code to call the cleanup routine. There are more efficient means of doing that, though.

The following code will delete all blank rows (except for those with vertically merged cells) in all tables in the active document.
Code:
Sub DelBlankRows()
Application.ScreenUpdating = False
Dim i As Long, j As Long
With ActiveDocument
  For i = .Tables.Count To 1 Step -1
    With .Tables(i)
      For j = .Rows.Count To 1 Step -1
        On Error Resume Next 'skip vertically merged cells
        With .Rows(j)
          If Trim(Replace(Replace(.Range.Text, Chr(13) & Chr(7), ""), Chr(160), "")) = "" Then .Delete
        End With
        On Error GoTo 0
      Next
    End With
  Next
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
automate macro for merged document (after merge) Automate document properties Ted C Word VBA 11 08-04-2014 06:31 AM
automate macro for merged document (after merge) Emailing from Merged Document (Complicated) Noxas Mail Merge 1 07-17-2014 06:14 PM
Save merged document as concatenated merge field values texas791 Word VBA 4 02-25-2014 07:35 PM
automate macro for merged document (after merge) Automate daily mail merge JCInfo Mail Merge 4 12-02-2013 05:12 PM
automate macro for merged document (after merge) Can I automate or make a macro for this? mkoenig Word VBA 1 01-31-2010 02:47 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:52 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft