Re: Creating New Documents At Each Heading

Tech-Archive recommends: Speed Up your PC by fixing your registry



Neither of those things should make any difference, nor why you thought to
mention the plus signs. Does each "heading" have the same style applied to
it?

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Fred Goldman" <FredGoldman@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:01B4EC15-871F-4D4E-831E-AFF1FD4DE703@xxxxxxxxxxxxxxxx
I am desperately trying to read this macro, but I'm too much of a novice to
understand what it says. However, this may help, some of the headings have
only one paragraph of text after them (not exclusively the ones that it's
skipping though), also the whole document is only one section.

"Fred Goldman" wrote:

I can't figure out why this is happening. I have 62 headings and it is
only
making 7 Documents and at random headings, no specific order. Any
suggestions? None of my styles have plus signs etc.

"Doug Robbins - Word MVP" wrote:

The following will need a bit of customising to suit the exact name of
your
Heading 1 style and also to use your template, but it does create a
separate
document for each heading 1 in the original document with each new
document
containing the heading 1 and the text that follows it before the next
heading 1

Dim myrange As Range, i As Long, newdoc As Document, j As Long
j = 1
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles( _
"Heading 1,Section,Main,h1,Heading1")
With Selection.Find
Do While .Execute(FindText:="", MatchWildcards:=False,
Wrap:=wdFindContinue, Forward:=True) = True
i = 1
Set myrange = Selection.Range
myrange.End = ActiveDocument.Range.End
Selection.Collapse wdCollapseEnd
For i = 2 To myrange.Paragraphs.Count
If myrange.Paragraphs(i).Style = ActiveDocument.Styles( _
"Heading 1,Section,Main,h1,Heading1") Then
Exit For
End If
Next i
myrange.End = myrange.Start + myrange.Paragraphs(i -
1).Range.End
Set newdoc = Documents.Add
newdoc.Range.FormattedText = myrange.FormattedText
newdoc.SaveAs "C:\aqs\newdoc" & j
newdoc.Close
j = j + 1
myrange.Cut
Loop
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Fred Goldman" <FredGoldman@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:D005503E-C0B2-47DD-AEAA-C26083231551@xxxxxxxxxxxxxxxx
Yeah, thanks for the replies, I tried both of them, and they didn't
work
(same problem). I would've posted there, but I thought it was too old
and
noone would be following it (you've got a good memory!).

"Andra" wrote:

did you see two replies to your 24jan message?

Fred Goldman wrote
I'm trying to create a documents from all the text between each
headin.
For
example Heading1 after that is BodyText1 and BodyText2, create a
single
document from that until the next Heading1 and so on.

Here's what I've got:

Dim myPara As Style
Dim myLastStyle As Style
Dim x As Long
Dim myTemplate As String
x = 1
myTemplate = Templates("C:\Templates\Chatzros Kadshechu.dot")
Set myLastStyle = ActiveDocument.Styles("LastParagraph")
Set myPara = ActiveDocument.Styles("Heading1")
Do
Do
Selection.MoveDown Unit:=wdParagraph, Count:=1,
Extend:=wdExtend
'At the following line it chokes because it selects
two
paragraphs
'which have two different styles
Loop While Selection.Style <> myPara
Selection.Copy
Documents.Add Template:=myTemplate
ActiveDocument.Range.PasteAndFormat
wdFormatOriginalFormatting
ActiveDocument.SaveAs FileName:="D" & x
ActiveDocument.Close
x = x + 1
Selection.MoveDown Unit:=wdParagraph, Count:=1
Loop Until Selection.Style = myLastStyle
End Sub








.



Relevant Pages

  • Re: NOT WORKING..Getting XLA files to work with Excel
    ... Dim FirstCell As Range, LastCell As Range ... Dim Wordstring As String ... If Tried2 Then Exit Sub ... Case "siRNA name" 'Heading That Goes to B ...
    (microsoft.public.excel.programming)
  • Why is my code not working the way I intend it to?
    ... Dim FirstCell As Range, LastCell As Range ... Dim Wordstring As String ... Dim NANDMVARSTRING As String ... Case "siRNA name" 'Heading That Goes to B ...
    (microsoft.public.excel.programming)
  • Re: Creating New Documents At Each Heading
    ... Heading 1 style and also to use your template, but it does create a separate ... Dim myPara As Style ... Set myLastStyle = ActiveDocument.Styles ...
    (microsoft.public.word.vba.general)
  • Re: Finding the number of the nearest previous heading level
    ... Dim aRange As Word.Range ... This bit of code works fine to get the heading number of the start of the ... Text para 1, but numbered as an outline level ...
    (microsoft.public.word.vba.general)
  • Re: VBA equivalent of StyleRef
    ... using a StyleRef in a header only searches within the scope of the ... Dim oRg2 As Range ... Dim summaryTbl As Table ... MsgBox "Did not find a preceding Heading 1 style." ...
    (microsoft.public.word.vba.general)