Split doc to many files

R

Roger Morris

I have several long Word documents (50 to 100 pages) that I would like
to split (save as) into many separate docs (files).

I have a Heading 1 at the start of what I would like to be the start of
each new doc.

Is there an easy way to do this please?

An Applescript (preferred) or VBA solution would be welcome.

Roger
 
R

Roger Morris

Roger Morris said:
I have several long Word documents (50 to 100 pages) that I would like
to split (save as) into many separate docs (files).

I have a Heading 1 at the start of what I would like to be the start of
each new doc.

Is there an easy way to do this please?

An Applescript (preferred) or VBA solution would be welcome.

Roger

Sorry, omitted to say: Mac OS 10.4.6 and Word 11.2

also

re length of docs - typically a 100 page document would produce nearly
100 separate new documents

Roger
 
J

John McGhie [MVP - Word and Word Macintosh]

Hi Roger:

Yes, there is. Look up "Master Documents" in the Help.

Basically, you need to

1) Save the file to a new name

2) Go into Master Document view

3) Select ALL

4) Hit Insert Subdocument

5) Hold down Shift and choose Save All from the File menu

Word will save each Heading 1 section as a new document, named after the
first string of text in the Heading 1.

Discard the Master Document and use only the subdocuments. If you attempt
editing in the Master Document view, you will get a short sharp lesson in
"How fast Master Documents corrupt".

Cheers

Sorry, omitted to say: Mac OS 10.4.6 and Word 11.2

also

re length of docs - typically a 100 page document would produce nearly
100 separate new documents

Roger

--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Microsoft MVP, Word and Word for Macintosh. Consultant Technical Writer
Sydney, Australia +61 (0) 4 1209 1410
 
R

Roger Morris

Sorry John,

I couldn't get that to work.

Wasn't sure about the "hit insert subdocument" but Save All simply saved
back the whole doc.

Looked at Help - there is a procedure to Split Subdocument but it seems
only to work with one heading (one split) at a time.



I thought I could make it happen with applescript
open document
get/cut the range from the first H1 to just before the next H1 -- ??
create new document
paste into / save newly created doc
repeat above

At the moment I haven't been able to select/cut the range which includes
the first H1 down to immediately before the next H1 - it's not a
consistent number of paragraphs throughout the (big) document.

Roger

John McGhie said:
Hi Roger:

Yes, there is. Look up "Master Documents" in the Help.

Basically, you need to

1) Save the file to a new name

2) Go into Master Document view

3) Select ALL

4) Hit Insert Subdocument

5) Hold down Shift and choose Save All from the File menu

Word will save each Heading 1 section as a new document, named after the
first string of text in the Heading 1.

Discard the Master Document and use only the subdocuments. If you attempt
editing in the Master Document view, you will get a short sharp lesson in
"How fast Master Documents corrupt".

Cheers


Roger
 
P

Paul Berkowitz

I have several long Word documents (50 to 100 pages) that I would like
to split (save as) into many separate docs (files).

I have a Heading 1 at the start of what I would like to be the start of
each new doc.

Is there an easy way to do this please?

An Applescript (preferred) or VBA solution would be welcome.

It can, but it would be easier if you had started a new section with each
Heading 1. Too late for that now?

In order to make new files, you have to tell us how you want to name them.
Suppose the original document is called "Document Blah.doc". Do you want the
separate docs to be called "Document Blah 1.doc", "Document Blah 2.doc",
etc. ? Or do you want the separate documents to have the names of the
Headings that begin them? Or what exactly? Presumably they should be saved
to the same folder as the long doc? There's always a possibility that a doc
of the same name already exists in that folder, necessitating a complicated
routine for re-naming them. IMO, it would be safer for the script to create
a new subfolder of the same name as the long doc (but without ".doc"
extension) or however you want (and the routine can check just _its_ name),
and make the separate docs within that.

--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.
 
R

Roger Morris

Paul Berkowitz said:
It can, but it would be easier if you had started a new section with each
Heading 1. Too late for that now?

I think so, these (big) Word docs are not new (unless a section break
could be inserted by a script?)

In fact they are various diaries and each Heading 1 styled text is a new
month. Each doc contains several years worth of data.

The text of the heading is consistent so can easily be changed and as it
contains both a month name and a 4 digit year number I intended to get
the new file names from there. There would be no duplicates.

I feel that I can handle the whole script with necessary repeats, new
doc creation etc except for the all important bit of selecting the one
month of data from the big document. So far, this is where I've failed.

This is the sequence (with para styles H1=Heading 1, N=Normal):
H1 "Diary for September 2001 (and a few other words)"
N "d1 ..." (arbitrary text)
N "d2 ..."
N "d3 ..." etc to month end (but not necessarily every day)
H1 "Diary for October 2001 (and a few other words)

My problem at present is finding out how to select and cut the portion:
"Diary for ..."
up to but not including the next "Diary for ..."

I supposed that cutting it to the clipboard would be best, I'm then only
ever searching for the first set of data.

Then all I have to do is create a new word doc, give it a name, paste
the text in and save it. I have done something like this before so
shouldn't have a problem (likewise the repeats and doc, sub folder
choosing/creating) - Does that sound like "famous last words"?

Mac OS 10.4.6 and Word 11.2

John McGhie suggested a way using Master Document processing but so far
I have not had any success with this either.

Roger
 
P

Paul Berkowitz

If I'm going to give you an example, it has to be something I can test. So
please answer how you want to name the separate files, as I asked in my last
post.

--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.
 
R

Roger Morris

Paul Berkowitz said:
If I'm going to give you an example, it has to be something I can test. So
please answer how you want to name the separate files, as I asked in my last
post.

OK, Thank you.

A (big) document is named "RM diary.doc"

The data in it is in groups like this:

"Diary for September 2001 (+ other words)"
"some text for day 1"
"some text for day 2"
"some text for day 3" etc for most days of the month
"Diary for October 2001 (+ other words)"
"some text for day 1"
etc - could be 3 - 5 years of data (up to 60 files)

I would like the separate files named (**) :
2001 September
2001 October
etc
and to be in a new sub folder named "RM diaries" in the same folder as
"RM diary.doc"

( ** ideally 01 to 12 for month names instead of January to December to
preserve calendar ordering but this could be easily changed by renaming
afterwards)

Assume there are no duplicate names.

The headings (for file names) can be identified by being formatted in
style "Heading 1". No other lines use this style.

The words at the start of the heading lines "Diary for mmmm yyyy " are
consistent so could be edited by find & replace all. There are other
(non consistent) words in the heading lines

I hope there is enough information here and look forward to your example
which will be very welcome.

Thank you
Roger
 
J

John McGhie [MVP - Word and Word Macintosh]

Hi Roger:

Did you read up on Master Documents in the Help? I use this feature all the
time for web publishing :)

Insert Subdocument is a button on the Master Document toolbar, which will
appear when you go into Master Document View, which you can do only from the
View menu.

H1 won't work. It must be "Heading 1" style... It can be any of the
"Heading..." series of styles, but it must be one of the built-in Word
heading styles. It should have told you in the help that this will work
only if the FIRST paragraph in your selection is the heading style level at
which you want to split the document. So if you want to split at the
Heading 3's, the first paragraph in your selection must be a Heading 3.

Ignore Split Subdocument, this is not what you want.

Cheers

Sorry John,

I couldn't get that to work.

Wasn't sure about the "hit insert subdocument" but Save All simply saved
back the whole doc.

Looked at Help - there is a procedure to Split Subdocument but it seems
only to work with one heading (one split) at a time.



I thought I could make it happen with applescript
open document
get/cut the range from the first H1 to just before the next H1 -- ??
create new document
paste into / save newly created doc
repeat above

At the moment I haven't been able to select/cut the range which includes
the first H1 down to immediately before the next H1 - it's not a
consistent number of paragraphs throughout the (big) document.

Roger




Roger

--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Microsoft MVP, Word and Word for Macintosh. Consultant Technical Writer
Sydney, Australia +61 (0) 4 1209 1410
 
C

CyberTaz

Hi John -

Point of clarification if you will - I thought Insert Subdocument was for
inserting a separate existing file into a Master as a Sub.

It seems to me that what the OP wants to do would better be handled by the
Create Subdocument button, since the content is already in the Master &
needs to be output to individual files.
 
J

John McGhie [MVP - Word and Word Macintosh]

Damn, I'm stupid!! I checked that TWICE and STILL wrote the wrong thing :)

You are utterly correct: The button is named "Create Subdocument" and I
cannot think why I chose the wrong one.

{Blush...} Senior moment, I think...


Hi John -

Point of clarification if you will - I thought Insert Subdocument was for
inserting a separate existing file into a Master as a Sub.

It seems to me that what the OP wants to do would better be handled by the
Create Subdocument button, since the content is already in the Master &
needs to be output to individual files.

--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Microsoft MVP, Word and Word for Macintosh. Consultant Technical Writer
Sydney, Australia +61 (0) 4 1209 1410
 
P

Paul Berkowitz

Well, it's all a muddle.

Have you seen John's suggestion, with CyberTaz's correction, to do this via
Master Document/Create Subdocuments? It's really the easiest way.

I thought I'd try to automate that for you, replacing the Heading 1 lines'
text with the substitutions you wanted perhaps. Te best way to automate is
always to let the application (Word) do the main work. Since it can make
subdocuments in a folder all in one step, I simply wanted to automate that
step rather than trying to do complicated messy text parsing. But the
AppleScript command corresponding to "Create Subdocuments" (equivalent to
VBA's AddFromRange command) is _missing_ from AppleScript!

I'm going to report that as a bug - it needs to be supplied forthwith. In
the meantime, it could be done as a VBA macro, I guess. Or I could try the
complicated, messy text parsing, scripting a Find of Heading 1 paragraphs,
etc. But since it's really so easy just to do it in the UI, I'm really not
sure this is worth the effort, is it?

--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.
 
R

Roger Morris

Hi John & CyberTaz

I wasn't going to say anything! (except thank you both)

I thought perhaps your /deliberate mistake/ was to encourage me to study
the help :)

Well, I did study the help and did discover "Create Subdocument" and
then the procedure you suggested worked well and fast.

I had to do some find&replace exercises to get the Heading 1 into a more
suitable form for a file name (Create Subdocs uses the whole para) but
that was not difficult.

Thank you

Roger



John McGhie said:
Damn, I'm stupid!! I checked that TWICE and STILL wrote the wrong thing :)

You are utterly correct: The button is named "Create Subdocument" and I
cannot think why I chose the wrong one.

{Blush...} Senior moment, I think...


Roger
 
R

Roger Morris

Hi Paul,

Thank you for your efforts - much appreciated. Let's hope the bg gets
corrected soon.

I did use John's suggestion and it did work albeit by using the whole
Heading 1 paragraph as the file name. That was easily smoothed.

I also continued with my efforts to use Applescript (complicated messy
text parsing) and eventually found out how to create, select and extend
ranges. ("Word 2004 AppleScript Reference" proved a great help in that
task)

The rest of the script was straightforward and that too now works
effectively, even if a lot slower than via Master Document/Create
Subdocuments.

I appreciate you point about letting the application do the main work.
The best solution is probably the Master Docs route but the Applescript
way has probably added more to my knowledge.

Thank you.

Roger



Paul Berkowitz said:
Well, it's all a muddle.

Have you seen John's suggestion, with CyberTaz's correction, to do this via
Master Document/Create Subdocuments? It's really the easiest way.

I thought I'd try to automate that for you, replacing the Heading 1 lines'
text with the substitutions you wanted perhaps. Te best way to automate is
always to let the application (Word) do the main work. Since it can make
subdocuments in a folder all in one step, I simply wanted to automate that
step rather than trying to do complicated messy text parsing. But the
AppleScript command corresponding to "Create Subdocuments" (equivalent to
VBA's AddFromRange command) is _missing_ from AppleScript!

I'm going to report that as a bug - it needs to be supplied forthwith. In
the meantime, it could be done as a VBA macro, I guess. Or I could try the
complicated, messy text parsing, scripting a Find of Heading 1 paragraphs,
etc. But since it's really so easy just to do it in the UI, I'm really not
sure this is worth the effort, is it?


Roger
 
C

CyberTaz

I hesitated to say anything the first time because I'm *always* the first to
admit that many others know more about many subjects than do I - including
subject that I'm certain I know quite well... But, of course, I had to go &
try it for myself! ;) - maybe a bit too heavy on the Foster's, John?

Regards |:>)
Bob Jones
[MVP] Office:Mac
 
P

Paul Berkowitz

You're certainly an easy person to help! ;-) You did all the work. That's
the way to learn, of course, as you say.

I was just about to show you that it might be possible to do it using 'do
Visual Basic' when I stumbled upon the fact that it _is_ possible to do it
in regular AppleScript. It's just hidden away. No one knew how (except
presumably the original developer, who never let on) - not even a Word
tester very familiar with the AppleScript model! The secret is that after
you set the view to master view:

It _is_ possible to make one subdocument at a time by AppleScript (having
first

set view type of view of active pane of active window to master view

then get the text range (text object) of the document:

set mainDocTextRange to mainDoc's text object

then making "a" subdocument from that range:

make new subdocument with properties {text object:mainDocTextRange}

actually makes all the subdocuments as determined by the Heading level of
the first paragraph of the text range! Just like the UI and like VBA's
"AddFromRange". In fact, it is AddFromRange! No need to re-implement a
separate command - it just needs to be explained in the Reference and,
briefly alluded to, at least, in the Dictionary.

The "peculiar" part is that if you set a variable to that

set subDoc1 to make new subdocument at mainDoc with properties {text
object:mainDocTextRange}

it returns just the first of the 5 or 10 or however many subdocs the process
makes (and so is not usually too useful, but never mind). No parsing is
necessary. If you follow the two lines above with

set allSubDocs to subdocuments of mainDoc

you now have access to all of them, can change the content of any paragraph
of any or all of them in a repeat loop, etc.

You have to make the folder were you want them saved using Finder scripting,
first. I also discovered (as you probably did too in the UI) that Word not
only doesn't like "/" in file names, which is fair enough (possible Unix
issues, though not really) but it also doesn't like "-" either, which is
silly. If you change the headings to "2001-09", "2001-10", "2001-11" etc.,
Word muddles them all as "2001", "20011", "20012", etc, - not what you want.
You could just leave out the punctuation but that makes it hard to read. I
found that using a bullet "€" works fine (1001€09, 2001€10, etc.) Here's the
script. You might want to look over the subroutine that gets the index
number of a list. Since your month names are text, that's the only (or best)
way to do it,


property monthList : {"January", "February", "March", "April", "May",
"June", "July", "August", "September", "October", "November", "December"}

tell application "Microsoft Word"
set mainDoc to active document
set view type of view of active pane of active window to master view
set {mainDocTextRange, maindocName, mainDocPath} to mainDoc's {text
object, name, path}
if maindocName ends with ".doc" then
set newFolderName to text 1 thru -5 of maindocName
else
beep
display dialog "First re-save the document with \".doc\" extension."
buttons {"Cancel"} default button 1 with icon 2 giving up after 100000 -- a
day
return
end if
set newFolderPath to mainDocPath & ":" & newFolderName & ":"
end tell

tell application "Finder" -- if folder exists already from previous runs,
use it
if not (exists folder newFolderPath) then make new folder at alias
mainDocPath with properties {name:newFolderName}
end tell

tell application "Microsoft Word"
make new subdocument at mainDoc with properties {text
object:mainDocTextRange}
set allSubDocs to subdocuments of mainDoc
repeat with i from 1 to (count allSubDocs)
set theSubDoc to item i of allSubDocs
set firstLine to content of text object of paragraph 1 of text
object of theSubDoc
set firstLine to my ConvertHeading(firstLine)
set content of text object of paragraph 1 of text object of
theSubDoc to firstLine
end repeat
save as mainDoc file name (newFolderPath & maindocName)
end tell


to ConvertHeading(firstLine)
set AppleScript's text item delimiters to {"20"}
set {firstBit, secondBit} to firstLine's {text item 1, text item 2}
set AppleScript's text item delimiters to {""}
set theMonth to last word of firstBit
set theMonth to my CollectUniqueItemIndex(monthList, theMonth)
if theMonth = 0 then
beep
display dialog "There is a heading without a proper month name (\""
& theMonth & "\")" buttons {"Cancel"} default button 1 with icon 2 giving up
after 100000
error number -128 -- quit
end if
set theMonth to text -2 thru -1 of ("0" & theMonth)
set theYear to "20" & text 1 thru 2 of secondBit
set firstLine to theYear & "€" & theMonth & return -- needs carriage
return
return firstLine
end ConvertHeading


to CollectUniqueItemIndex(theList, theItem) -- the Item can be string,
number, constant, app object or list

set theIndex to 0
repeat with i from 1 to (count theList)
set aListMember to item i of theList
if aListMember = theItem then
set theIndex to i
exit repeat
end if
end repeat

return theIndex

end CollectUniqueItemIndex






--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.
 
J

John McGhie [MVP - Word and Word Macintosh]

Well, I¹m glad you two have managed to get it to work from AppleScript,
because I have NEVER had any success getting it to work properly from VBA
:)

What I have always wanted to do is loop through the collection of created
subdocuments and fiddle with their file names. I¹ve never been able to get
hold of the collection :)

Cheers


You're certainly an easy person to help! ;-) You did all the work. That's the
way to learn, of course, as you say.

I was just about to show you that it might be possible to do it using 'do
Visual Basic' when I stumbled upon the fact that it _is_ possible to do it in
regular AppleScript. It's just hidden away. No one knew how (except presumably
the original developer, who never let on) - not even a Word tester very
familiar with the AppleScript model! The secret is that after you set the view
to master view:

It _is_ possible to make one subdocument at a time by AppleScript (having
first

set view type of view of active pane of active window to master view

then get the text range (text object) of the document:

set mainDocTextRange to mainDoc's text object

then making "a" subdocument from that range:

make new subdocument with properties {text object:mainDocTextRange}

actually makes all the subdocuments as determined by the Heading level of the
first paragraph of the text range! Just like the UI and like VBA's
"AddFromRange". In fact, it is AddFromRange! No need to re-implement a
separate command - it just needs to be explained in the Reference and, briefly
alluded to, at least, in the Dictionary.

The "peculiar" part is that if you set a variable to that

set subDoc1 to make new subdocument at mainDoc with properties {text
object:mainDocTextRange}

it returns just the first of the 5 or 10 or however many subdocs the process
makes (and so is not usually too useful, but never mind). No parsing is
necessary. If you follow the two lines above with

set allSubDocs to subdocuments of mainDoc

you now have access to all of them, can change the content of any paragraph of
any or all of them in a repeat loop, etc.

You have to make the folder were you want them saved using Finder scripting,
first. I also discovered (as you probably did too in the UI) that Word not
only doesn't like "/" in file names, which is fair enough (possible Unix
issues, though not really) but it also doesn't like "-" either, which is
silly. If you change the headings to "2001-09", "2001-10", "2001-11" etc.,
Word muddles them all as "2001", "20011", "20012", etc, - not what you want.
You could just leave out the punctuation but that makes it hard to read. I
found that using a bullet "€" works fine (1001€09, 2001€10, etc.) Here's the
script. You might want to look over the subroutine that gets the index number
of a list. Since your month names are text, that's the only (or best) way to
do it,


property monthList : {"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"}

tell application "Microsoft Word"
set mainDoc to active document
set view type of view of active pane of active window to master view
set {mainDocTextRange, maindocName, mainDocPath} to mainDoc's {text
object, name, path}
if maindocName ends with ".doc" then
set newFolderName to text 1 thru -5 of maindocName
else
beep
display dialog "First re-save the document with \".doc\" extension."
buttons {"Cancel"} default button 1 with icon 2 giving up after 100000 -- a
day
return
end if
set newFolderPath to mainDocPath & ":" & newFolderName & ":"
end tell

tell application "Finder" -- if folder exists already from previous runs, use
it
if not (exists folder newFolderPath) then make new folder at alias
mainDocPath with properties {name:newFolderName}
end tell

tell application "Microsoft Word"
make new subdocument at mainDoc with properties {text
object:mainDocTextRange}
set allSubDocs to subdocuments of mainDoc
repeat with i from 1 to (count allSubDocs)
set theSubDoc to item i of allSubDocs
set firstLine to content of text object of paragraph 1 of text object
of theSubDoc
set firstLine to my ConvertHeading(firstLine)
set content of text object of paragraph 1 of text object of theSubDoc
to firstLine
end repeat
save as mainDoc file name (newFolderPath & maindocName)
end tell


to ConvertHeading(firstLine)
set AppleScript's text item delimiters to {"20"}
set {firstBit, secondBit} to firstLine's {text item 1, text item 2}
set AppleScript's text item delimiters to {""}
set theMonth to last word of firstBit
set theMonth to my CollectUniqueItemIndex(monthList, theMonth)
if theMonth = 0 then
beep
display dialog "There is a heading without a proper month name (\"" &
theMonth & "\")" buttons {"Cancel"} default button 1 with icon 2 giving up
after 100000
error number -128 -- quit
end if
set theMonth to text -2 thru -1 of ("0" & theMonth)
set theYear to "20" & text 1 thru 2 of secondBit
set firstLine to theYear & "€" & theMonth & return -- needs carriage
return
return firstLine
end ConvertHeading


to CollectUniqueItemIndex(theList, theItem) -- the Item can be string, number,
constant, app object or list

set theIndex to 0
repeat with i from 1 to (count theList)
set aListMember to item i of theList
if aListMember = theItem then
set theIndex to i
exit repeat
end if
end repeat

return theIndex

end CollectUniqueItemIndex


--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Microsoft MVP, Word and Word for Macintosh. Consultant Technical Writer
Sydney, Australia +61 (0) 4 1209 1410
 
P

Paul Berkowitz

You do it in VBA the same way, John. Probably the "trick" is to remember
that a Subdocument, unlike a Document, does not have Paragraphs: first you
have to get the Range of the Subdoc, then get its Paragraphs, then their
Ranges. Here's a simple example that strips the first 10 characters of each
Subdocument's first paragraph - the Heading line that determines the Subdoc
division and becomes the new file name for each file. So start out with all
such headings longer than 10 characters - I used Roger's "Diary for "
example. Or just strip 1 character as a test, if you wish. I've left in the
Debug.Print lines so you can see what's going on. I used 5 Heading 1 lines
to make 5 Subdocs.


Sub ManageSubdocs()

Dim subDoc As Subdocument
Dim c As Long, firstLine As String

ActiveWindow.ActivePane.View.Type = wdMasterView
With ActiveDocument.Subdocuments
.Expanded = True
.AddFromRange ActiveDocument.Range
c = .Count
End With

Debug.Print c

For Each subDoc In ActiveDocument.Subdocuments
firstLine = subDoc.Range.Paragraphs(1).Range.Text
Debug.Print firstLine
firstLine = Right(firstLine, Len(firstLine) - 10)
subDoc.Range.Paragraphs(1).Range.Text = firstLine
Next subDoc


End Sub


--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.



From: "John McGhie [MVP - Word and Word Macintosh]" <[email protected]>
Newsgroups: microsoft.public.mac.office.word
Date: Sat, 13 May 2006 15:59:34 +1000
Conversation: Split doc to many files
Subject: Re: Split doc to many files

Well, I¹m glad you two have managed to get it to work from AppleScript,
because I have NEVER had any success getting it to work properly from VBA
:)

What I have always wanted to do is loop through the collection of created
subdocuments and fiddle with their file names. I¹ve never been able to get
hold of the collection :)

Cheers
 
P

Paul Berkowitz

You do it in VBA the same way, John. Probably the "trick" is to remember that
a Subdocument, unlike a Document, does not have Paragraphs: first you have to
get the Range of the Subdoc, then get its Paragraphs, then their Ranges.

Or maybe the other "trick" is that you have to make or specify a folder for
the new files to be saved to (contained within the the FileName argument of
the SaveAs Method). (According to the Help, if you use the default location
where the original document is already saved, the master document which gets
re-saved to the same location should overwrite the original without an error
or dialog, but I haven't tried that yet.) If you specify a folder location
that doesn't exist yet (e.g. a new subfolder with the same name as the
master doc, minus the .doc extension), it will error, at least on the Mac.
I'd imagine it's the same on Windows - perhaps that's the issue you ran into
- if it doesn't get made automatically there. On the Mac, you need to make
the new folder using Finder AppleScripting, which would have to be done via
MacScript in a VBA macro. I'm sure you can do it via regular VB on Windows
if you know how.

It would be nice if the FileName argument of SaveAs and its AppleScript
equivalent 'save as' made any needed folder(s) named in the FileName
argument automatically, without any preliminary code needed. For all I know,
maybe it does actually work that way on Windows? It doesn't on the Mac - you
need to make the folder first using Finder AppleScript (or 'do shell script
"rmdir"' Unix shell scripting within AppleScript) or MacScript in VBA.

--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.
 
J

John McGhie [MVP - Word and Word Macintosh]

Hi Paul:

Your first guess would be the one. A subdocument "should" be a document
object and should contain paragraphs :) If it doesn't that would be why
activedocument.subdocuments didn't work, and I didn't have time to fiddle
around to find out why.

If you do much with Master Documents, you do not create extra subfolders; if
you do, you can never move the master document because it breaks all the
internal links.

If you leave them all in the same folder, you can pick the folder up and
move it anywhere you like: the subdocuments will automatically re-attach
when the master is opened.

We'll all get a lot better at this in the next version. In the XML format,
master documents will finally be "fixed" so you can use them without
corruption. So finally, 20 years after it was invented, the Master Document
feature will be useful :)

Cheers

Or maybe the other "trick" is that you have to make or specify a folder for
the new files to be saved to (contained within the the FileName argument of
the SaveAs Method). (According to the Help, if you use the default location
where the original document is already saved, the master document which gets
re-saved to the same location should overwrite the original without an error
or dialog, but I haven't tried that yet.) If you specify a folder location
that doesn't exist yet (e.g. a new subfolder with the same name as the master
doc, minus the .doc extension), it will error, at least on the Mac. I'd
imagine it's the same on Windows - perhaps that's the issue you ran into - if
it doesn't get made automatically there. On the Mac, you need to make the new
folder using Finder AppleScripting, which would have to be done via MacScript
in a VBA macro. I'm sure you can do it via regular VB on Windows if you know
how.

It would be nice if the FileName argument of SaveAs and its AppleScript
equivalent 'save as' made any needed folder(s) named in the FileName argument
automatically, without any preliminary code needed. For all I know, maybe it
does actually work that way on Windows? It doesn't on the Mac - you need to
make the folder first using Finder AppleScript (or 'do shell script "rmdir"'
Unix shell scripting within AppleScript) or MacScript in VBA.


--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Microsoft MVP, Word and Word for Macintosh. Consultant Technical Writer
Sydney, Australia +61 (0) 4 1209 1410
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top