PDA

View Full Version : Solved: save each page as separate document but save as file name?



mancubus
01-27-2011, 01:23 AM
hi board.


i want to save each page of the doc (25-100 pages) as separate files.

how can i do that? and more important, how can i define a variable to pick the SaveAs filemane from each page?

company logo
document number

To: xxxxxx yyyy
var var var var Standard Text

so the variable is between words "To" and "Standard Text" and in a line just after the "To"s line, is often 2 words but may be 1 or more than two.

any ideas?

thanks in advance.

ps: using word 2007. but output files in word2003

macropod
01-27-2011, 02:12 AM
See: http://gregmaxey.mvps.org/Document_Splitter.htm

mancubus
01-27-2011, 03:17 AM
thanks Paul.
installed and run on a sample file. but files' names are page numbers in the source doc with a prefix. and there is a disclamer in header and footer.

macropod
01-27-2011, 03:47 AM
Hi mancubus,

You can easily enough open the template in Word to delete the disclaimer in the header & footer.

For the variables you want to include in the filename, you would need to modify the code behind the template's useform to find & extract the strings from the document (excluding any characters that aren't valid in a filename), then add the concatenated strings to the save process.

Without knowing more about the layouts of the various pages, it would be hard to give specifi advice on this. However, it does seem like a wildcard Find operation might do the job of finding the strings for parsing.

mancubus
01-27-2011, 06:47 AM
thanks.

header/footer part done.
file name part not.
but i think i will use excel vba to ren file names.

thanks for help.

mancubus
01-27-2011, 06:58 AM
solved with Paul's advice on Greg Maxey's add-in and excel vba.


someone who will be interested in the topic may see my efforts below

if it were excel, my solution would be as follows.

Sub Find_()

Dim xRow As Long, xCol As Long
Dim str1Rng As Range
Dim srcStr1 As String, srcStr2 As String, fName As String

srcStr1 = "To:"
srcStr2 = "Standard Text"

Set str1Rng = Cells.Find(What:=srcStr1, After:=Cells(1, 1), _
LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=True)

xRow = Cells.Find(What:=srcStr2, After:=str1Rng, _
LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=True).Row

xCol = Cells.Find(What:=srcStr2, After:=str1Rng, _
LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=True).Column

fName = Left(Trim(Cells(xRow, xCol)), Len(Trim(Cells(xRow, xCol))) - (Len(Trim(srcStr2)) + 1))

'MsgBox fName

End Sub



i tried something below for word vba


Sub ffnd()

Selection.Find.ClearFormatting
With Selection.Find
.Text = "To"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute

Selection.HomeKey Unit:=wdLine
Selection.MoveDown Unit:=wdLine, Count:=Count + 1
Selection.MoveRight Unit:=wdWord, Count:=4
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend

End Sub