Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-08-2022, 07:28 PM
macropod's Avatar
macropod macropod is online now Mailmerge problem using Database field Windows 10 Mailmerge problem using Database field Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
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


Quote:
Originally Posted by Tesla View Post
Any help to modify the VBA code below so that it can add totals for each columns and also to remove "£" on attached mail merge document?
It seems you haven't even attempted to adapt the code from your other thread. The code required for this project is way simpler:
Code:
Sub MailMergeToDoc()
Application.ScreenUpdating = False
Dim Rng As Range, t As Long, r As Long, c As Long
ActiveDocument.MailMerge.Execute
With ActiveDocument.Range
  For t = 1 To .Tables.Count
    With .Tables(t)
      .AllowAutoFit = False
      .Range.ParagraphFormat.Alignment = wdAlignParagraphRight
      .Rows.Alignment = wdAlignRowCenter
      .Rows(1).HeadingFormat = True
      .Rows(1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
      .Columns.PreferredWidthType = wdPreferredWidthPoints
      .Columns.PreferredWidth = InchesToPoints(0.625)
      .Columns(1).PreferredWidth = InchesToPoints(0.75)
      .Columns(10).PreferredWidth = InchesToPoints(0.75)
      .Rows.Add: r = .Rows.Count
      .Cell(r, 1).Range.Text = "TOTAL:"
      .Rows(r).Range.Font.Bold = True
      For c = 3 To 9
        Set Rng = .Cell(r, c).Range
        Rng.Collapse wdCollapseStart
        Rng.Fields.Add Rng, wdFieldEmpty, "=SUM(ABOVE) \# £,#0", False
      Next
    End With
  Next
  .Fields.Unlink
End With
Set Rng = Nothing
Application.ScreenUpdating = True
End Sub
And, if you don't want to retain the £ characters being output by the DATABASE field, surely the appropriate way to do that is to not have the DATABASE field insert them in the first place.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #2  
Old 04-09-2022, 12:33 PM
Tesla Tesla is offline Mailmerge problem using Database field Windows 7 32bit Mailmerge problem using Database field Office 2007
Advanced Beginner
Mailmerge problem using Database field
 
Join Date: Sep 2018
Posts: 59
Tesla is on a distinguished road
Default

The code works, thank you
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Ref field to Database field doesn't update properly in Mailmerge huynguyen865 Mail Merge 1 08-30-2021 07:30 AM
Mailmerge problem using Database field Macro to insert an image to a word mailmerge document based on the value of a mailmerge field? Jake93 Mail Merge 3 07-02-2019 05:38 PM
Mailmerge problem using Database field database field table lines Sarki76 Mail Merge 3 06-26-2019 03:13 PM
Database field cell alignment scubadunc Mail Merge 9 08-12-2014 11:02 PM
Mailmerge problem using Database field insert database as field david_89_ Mail Merge 3 03-26-2014 06:02 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:57 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