Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-17-2017, 04:52 AM
Articade Articade is offline Saving a file name as certain founds on a specified line Windows 7 64bit Saving a file name as certain founds on a specified line Office 2010 64bit
Novice
Saving a file name as certain founds on a specified line
 
Join Date: Nov 2017
Posts: 1
Articade is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 11-17-2017, 06:02 AM
gmayor's Avatar
gmayor gmayor is offline Saving a file name as certain founds on a specified line Windows 10 Saving a file name as certain founds on a specified line Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,105
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #3  
Old 11-17-2017, 01:17 PM
macropod's Avatar
macropod macropod is offline Saving a file name as certain founds on a specified line Windows 7 64bit Saving a file name as certain founds on a specified line Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

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]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
saving a file Beebop Word 1 08-30-2017 09:20 PM
Saving a file name as certain founds on a specified line 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 a file name as certain founds on a specified line 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

Other Forums: Access Forums

All times are GMT -7. The time now is 11:39 PM.


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