#1
|
|||
|
|||
Saving a file name as certain founds on a specified line
Hello. (using word and excel 2010) I am working off of microsoft word and
right now, my code is used to: 1) Separate mail merged pages, remove the section breaks, and set default values (font, paragraph spacing). 2) Save each Separate page as a separate file. (only saves as numbers). What I am trying to do is fix the saving part. I want to make it so the macro finds the line with the word "To:", and save the file name as different words on that line, for example, the line would be: To: Mr Jacob A Compton I would want to save the file name as Mr Jacob Jacob A Compton. How do I get this to work? Thank you for your help. Option Explicit Sub DeleSectionBreaks() Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "^b" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchByte = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = False .MatchFuzzy = False End With Selection.Find.Execute Replace:=wdReplaceAll End Sub Sub DefaultSettings() Selection.WholeStory Selection.Font.Name = "Courier New" Selection.Font.Size = 12 With Selection.ParagraphFormat .SpaceBefore = 0 .SpaceBeforeAuto = False .SpaceAfter = 0 .SpaceAfterAuto = False .LineSpacingRule = wdLineSpaceSingle .LineUnitBefore = 0 .LineUnitAfter = 0 .WordWrap = True End With With Selection.PageSetup .LineNumbering.Active = False .Orientation = wdOrientPortrait .TopMargin = InchesToPoints(1.2) .BottomMargin = InchesToPoints(0.5) .LeftMargin = InchesToPoints(1) .RightMargin = InchesToPoints(1) .Gutter = InchesToPoints(0) .HeaderDistance = InchesToPoints(0.5) .FooterDistance = InchesToPoints(0.5) .PageWidth = InchesToPoints(8.5) .PageHeight = InchesToPoints(11) .FirstPageTray = wdPrinterDefaultBin .OtherPagesTray = wdPrinterDefaultBin .OddAndEvenPagesHeaderFooter = False .DifferentFirstPageHeaderFooter = False .VerticalAlignment = wdAlignVerticalTop .SuppressEndnotes = False .MirrorMargins = False .TwoPagesOnOne = False .BookFoldPrinting = False .BookFoldRevPrinting = False .BookFoldPrintingSheets = 1 .GutterPos = wdGutterPosLeft .LayoutMode = wdLayoutModeDefault End With End Sub Sub AllSectionsToSubDoc() Dim x As Long Dim Sections As Long Dim Doc As Document Application.ScreenUpdating = False Application.DisplayAlerts = False Set Doc = ActiveDocument Sections = Doc.Sections.Count For x = Sections - 1 To 1 Step -1 Doc.Sections(x).Range.Copy Documents.Add ActiveDocument.Range.Paste Call DeleSectionBreaks Call DefaultSettings ActiveDocument.SaveAs (Doc.Path & "\" & x & ".doc") ActiveDocument.Close False Next x Application.ScreenUpdating = True Application.DisplayAlerts = True End Sub |
#2
|
||||
|
||||
Why not save yourself a lot of trouble and merge to separate pages - see
http://www.gmayor.com/individual_merge_letters.htm. or split the document http://www.gmayor.com/MergeAndSplit.htm
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
||||
|
||||
See also:
• Send Mailmerge Output to Individual Files; and • Split Merged Output to Separate Documents, in the Mailmerge Tips and Tricks 'Sticky' thread on this forum: https://www.msofficeforums.com/mail-...ps-tricks.html
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
saving a file | Beebop | Word | 1 | 08-30-2017 09:20 PM |
Auto Save Every Page(s) as a separate file, and name each new file automatically by the first line? | commissarmo | Word VBA | 3 | 03-14-2015 12:53 AM |
Word does not ask do i want to overwrite a file on saving a file | sam2149 | Word | 2 | 03-24-2014 04:18 AM |
Saving mpp file as XML | OTPM | Project | 7 | 02-26-2014 07:22 AM |
Line appearing over left and top of image when saving | rs14smith | Word | 17 | 01-04-2012 11:02 AM |