![]() |
#1
|
|||
|
|||
![]()
I am working on a Word document that uses an export from our accounting software. We have no control over how this data is provided to us. This is for listing transactions and emailing them a remittance. There is a "Table" in the doc that is really just one field per line. They send the whole line as one field and if the line is blank we get several spaces, so line suppression is not working.
I would like to clean up the fields and remove the leading and tailing spaces. It would be even better if I could split a field into several to become a better output. Sometimes their output field wraps around to the next line and the "Columns do not line up. I tried adding =Trim(<<mergefield>>) but it did not like that either. I feel like we can do this with EditDataSource but the only examples I can find are about adding a line, not looping through each, and modifying the value. This is what I have been trying but Datafields.Value is Read Only. Code:
Sub CleanData() Dim masterDoc As Document, singleDoc As Document, field As String, cols As Integer, rows As Integer Set masterDoc = ActiveDocument Set singleDoc = Documents.Add If masterDoc.MailMerge.DataSource.Type = _ wdMergeInfoFromWord Then With masterDoc.MailMerge .EditDataSource For Each afield In .DataSource.DataFields field = Trim(afield.Value) afield.Value = field singleDoc.Content.InsertAfter Text:=afield.Name & ":" & afield.Value & vbCrLf Next afield End With End If End Sub Here is some sample data. It is the L## fields that are the biggest issue. sampleData.txt This is the issue we get with some of the remittances: Bad: RemirBadLines.png Normal: remitGoodLines.png I hope this makes sense, I was interrupted a few times writing this. Thanks for any help, Luke |
Tags |
editdatasource, mailmerge field, vba |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
jeffreybrown | Word VBA | 2 | 09-04-2018 07:36 PM |
Data Entry - Getting spreadsheets back with excess space but the TRIM function doesn't work | jhato160 | Excel | 5 | 06-17-2016 04:06 AM |
Merge fields in Word and source data from Excel | SteveVai | Mail Merge | 3 | 03-13-2014 05:25 AM |
![]() |
freefalladdict | Word | 3 | 01-08-2012 02:23 PM |
How do I set up the fields in mail merge word 07 from my data base | mbcrabber | Mail Merge | 4 | 06-06-2010 01:25 PM |