Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-17-2014, 08:37 AM
Baldeagle Baldeagle is offline Use of Macro SplitMergeForm Windows 8 Use of Macro SplitMergeForm Office 2013
Advanced Beginner
Use of Macro SplitMergeForm
 
Join Date: Apr 2012
Posts: 62
Baldeagle is on a distinguished road
Default Use of Macro SplitMergeForm

Last year I got considerable help in sending emails with 2 attachments. This year I have hit a snag. When I merge one of my attachments (see A) into a document with all the different individual forms in one document (see one such form in B) there is some distortion of the layout. But when I use the Macro SplitMergeForm it distorts the layout even more (see C which is the form to be attached to the emails).

Is there any way that the original layout can be maintained for the attachment?

My macro is as follows -
Code:
Sub SplitMergeForm()
'
' SplitMergeForm Macro
'
' splitter Macro modified to save individual Gift Aid (and Tax) Allocation Forms with

' information from data source. The filename data must be added to

' the top of the merge letter - see web article.

Dim sName As String
Dim docName As String
Dim Letters As String
Dim Counter As Long
Dim oDoc As Document
Dim oNewDoc As Document
Set oDoc = ActiveDocument
oDoc.Save

Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter < Letters
     Application.ScreenUpdating = False
     With Selection

          .HomeKey Unit:=wdStory
          .EndKey Unit:=wdLine, Extend:=wdExtend
          .MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend

     End With
     sName = Selection
     docName = "C:\Our Folders\BWMC\Form " & sName & ".doc"

     oDoc.Sections.First.Range.Cut
     Set oNewDoc = Documents.Add

    'Documents are based on the Normal template

    'To use an alternative template follow the link.
     With Selection
         .Paste
         .HomeKey Unit:=wdStory
         .MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
         .Delete
     End With
     oNewDoc.SaveAs FileName:=docName, _
        FileFormat:=wdFormatDocument, _
        AddToRecentFiles:=False
     ActiveWindow.Close
     Counter = Counter + 1
     Application.ScreenUpdating = True
Wend

oDoc.Close wdDoNotSaveChanges

End Sub

Attached Files
File Type: doc A.doc (55.5 KB, 11 views)
File Type: doc B.doc (54.5 KB, 10 views)
File Type: doc C.doc (55.5 KB, 9 views)
Reply With Quote
  #2  
Old 07-17-2014, 05:58 PM
macropod's Avatar
macropod macropod is offline Use of Macro SplitMergeForm Windows 7 32bit Use of Macro SplitMergeForm Office 2010 32bit
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

There are multiple issues going on here. Your various documents :
• use different versions of the same Styles
• have manual formatting overriding those Style defintions
• have a mix of in-line and floating tables
All of which make it difficult to control the formatting when copying content between them.

The most basic issue concerns the Styles. To see how a given document differs from its own Style definitions, use Ctrl-A to select the entire document, then press Ctrl-Spacebar. This removes all the manual formatting and reveals the underlying formats. Do that for all the documents, then compare the formats of the paragraphs using the Normal Style, for example, and you'll see what the underlying differences are. If you're going to copy content between documents, you really do need to define and use their Styles consistently. Granted, there are ways around this, but it's better to deal with the problem at its source, rather than applying workarounds. Apart from anything else, learning to use Styles properly will make is easier to manage all your documents, especially those with complex formatting.

As for the tables, I'd suggest merging all the content into a single table, with a mix of row heights, cell widths, columns and borders for the lower part. That will give you greater control over the overall layout. Indeed, instead of the two-column page layout you're now using, you could use a single-column layout with a table that has an extra column with just one cell merged across all the row and all the data on the right-hand side of the page placed into that cell.

As a temporary workaround for the replication problems, you might try changing:
.Paste
to:
.PasteAndFormat (wdFormatOriginalFormatting)
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 07-18-2014, 07:29 AM
Baldeagle Baldeagle is offline Use of Macro SplitMergeForm Windows 8 Use of Macro SplitMergeForm Office 2013
Advanced Beginner
Use of Macro SplitMergeForm
 
Join Date: Apr 2012
Posts: 62
Baldeagle is on a distinguished road
Default Progress

Thanks for taking the time to look into my problem - I had started to wonder last night whether it was something to do with margins. I must study styles and see if I can make things simpler in future!

I have taken your temporary workaround suggestion in the meantime. But while the main issue is resolved there are 2 minor issues. I am attaching the latest version of the 3 files that I attached originally - A is the master document, B is the first page of the merged data and C is the first file created by the Macro - SplitMergeForm (as revised with the inclusion of .PasteAndFormat (wdFormatOriginalFormatting).

Can you throw any light on why the email address and part of the heading is missing from the top of C? And is there any way to eliminate the second page (which is totally blank)?
Attached Files
File Type: doc A.doc (59.0 KB, 9 views)
File Type: doc B.doc (54.5 KB, 9 views)
File Type: doc C.doc (55.0 KB, 10 views)
Reply With Quote
  #4  
Old 07-18-2014, 03:44 PM
macropod's Avatar
macropod macropod is offline Use of Macro SplitMergeForm Windows 7 32bit Use of Macro SplitMergeForm Office 2010 32bit
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

I'm not sure why your macro might be omitting part of the page. As for the blank pages, that's because you're inserting the Section break that goes with each letter.

Might I suggest you discard the current process and instead drive the merge with the 'Send Mailmerge Output to Individual Files' macro here: https://www.msofficeforums.com/mail-...ps-tricks.html. With that macro, your individual files will be generated when you do the merge and their formatting will be preserved. As an added bonus, the output can be saved as PDFs and/or docx files at the same time.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 07-19-2014, 12:39 PM
Baldeagle Baldeagle is offline Use of Macro SplitMergeForm Windows 8 Use of Macro SplitMergeForm Office 2013
Advanced Beginner
Use of Macro SplitMergeForm
 
Join Date: Apr 2012
Posts: 62
Baldeagle is on a distinguished road
Default Thanks!

Many thanks for your guidance - I have adapted the alternative macro that you suggested and have successfully sent the batch of emails with the relevant attachments.

Your help is very much appreciated.
Reply With Quote
Reply

Tags
attachments, layout, merge



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro Needed to bold specific lines and Macro to turn into CSV anewteacher Word VBA 1 05-28-2014 03:59 PM
custom icon, undo/redo for macro, permanent macro Rapier Excel 0 08-05-2013 06:30 AM
How do I assign a macro to a button when the macro is in my personal workbook? foolios Excel Programming 2 07-27-2011 02:41 PM

Other Forums: Access Forums

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