![]() |
|
#1
|
|||
|
|||
|
Hi as in the title, my code is going through a word document, heading by heading.
and i need to know if the next heading is the last heading, because with every heading i am opening a <case> in XML and i need to close them at the end</case>. So if you have an idea, let me know. thanks! |
|
#2
|
||||
|
||||
|
Is this for a particular Heading Style, or for any Heading Style?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#3
|
|||
|
|||
|
Quote:
And an other question: how do i select a header, to print it somewhere else? i used to write Selection.GoTo what:=wdGoToHeading, which:=wdGoToNext Selection.HomeKey Unit:=wdLine Selection.EndKey Unit:=wdLine, Extend:=wdExtend but what if the header has two or three lines? Do i need to take "Selection."? Thanks |
|
#4
|
||||
|
||||
|
The basic tagging can be done with Find/Replace code like:
Code:
Sub TagHeadings()
Dim i As Long
For i = 1 To 9
With ActiveDocument.Range
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchWildcards = False
.Style = "Heading " & i
.Execute
End With
Do While .Find.Found
.InsertBefore "<case>"
.Characters.Last.InsertBefore "</case>"
.Collapse wdCollapseEnd
.Find.Execute
Loop
End With
Next
End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#5
|
|||
|
|||
|
Code:
Do While .Find.Found .InsertBefore "<case>" .Characters.Last.InsertBefore "</case>" .Collapse wdCollapseEnd .Find.Execute Loop |
|
#6
|
||||
|
||||
|
Hi Gerry,
I was intentionally inserting the "</case>" into the end of the heading paragraph, rather than into the start of the one after it; otherwise, I'd have just used .InsertAfter without reference to .Characters.Last. I also deliberately implement a loop in anticipation that the OP might want to add some other content in or around either or both of the "<case>" and "</case>" strings (e.g. the heading level and/or the index # of that heading). It would actually be more efficient to use ReplaceAll for what has been specified.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
How to add space between heading number and heading text
|
Dr Wu | Word | 4 | 07-15-2018 03:52 AM |
How to Restore Heading 1, Heading 2, etc. within a Word Document
|
cheech1981 | Word | 9 | 01-11-2017 02:14 AM |
Heading title before heading number
|
johnor999 | Word | 4 | 12-06-2013 12:39 AM |
| Control the size of space between heading number and heading text | Dr Wu | Word | 1 | 07-17-2013 12:24 PM |
Styles: Heading 4 stuck at same heading number
|
Hallet | Word | 1 | 05-31-2012 02:37 PM |