Re: Checking whether paragraphs have been formatted with outline n
- From: Lene Fredborg <lf@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 21 Feb 2009 11:05:01 -0800
You are welcome. I am glad I could help.
--
Regards
Lene Fredborg - Microsoft MVP (Word)
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
"andreas" wrote:
On Feb 18, 3:13 pm, Lene Fredborg <l...@xxxxxxxxxxxxxxxxxxxxxxxxx>.
wrote:
I tested the macro without any error before posting it and it worked - and it
still does. I now tried to copy the macro from the Internet and I found that
your problem could be due to an erroneous line break that appeared when you
copied the macro from the Internet.
Check this part of the macro:
If oPara.Range.InRange(ActiveDocument.TablesOfContents(1).Range) = True Then
GoTo SkipPara
Is it all on _one_ line? (Goto SkipPara may have moved to next line and this
is not marked by red in the editor). Make sure to combine the string in one
line. Alternatively, add an extra “End If” below it.
Does this solve the problem?
Note: When posting the code, I forgot to remove the “Dim i as long” which is
not used. You can delete it if you wish.
--
Regards
Lene Fredborg - Microsoft MVP (Word)
DocTools - Denmarkwww.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
"andreas" wrote:
On 17 Feb., 10:42, Lene Fredborg <l...@xxxxxxxxxxxxxxxxxxxxxxxxx>
wrote:
The reason why I only included the heading number in the message was that a
MsgBox only allows less than 1024 characters (but I did not explicitly tell
that…). If many and long headings were found, you could hit the max.. limit so
that the lasts paragraphs would be missing in the message.
About skipping the TOC: This could be done in different ways. Below you will
find a new version of the macro where a paragraph will be skipped if it is in
the (first) table of contents in the document. If your document contains more
than one TOC, you would need to check for other TOCs too. You will need to
incorporate your own changes in the new macro version:
Sub FindAndMarkManuallyNumberedParagraphs()
Dim oPara As Paragraph
Dim strMsg As String
Dim oArray As Variant
Dim n As Long
Dim nToc As Long
Application.ScreenUpdating = False
'Find number of TOCs
nToc = ActiveDocument.TablesOfContents.Count
'Create an array of strings to check
'Here only 5 levels in format 1 or 1., 1.1, 1.1.1, 1.1.1.1, 1..1.1..1.1
are included
'Also, the code will not find e.g. 12.11.1 - to do this, include more
variations in the array
oArray = Array("# ", "#" & vbTab, _
"#. ", "#." & vbTab, _
"#.# ", "#.#" & vbTab, _
"#.#.# ", "#.#.#" & vbTab, _
"#.#.#.# ", "#.#.#.#" & vbTab, _
"#.#.#.#.# ", "#.#.#.#.#" & vbTab)
For n = LBound(oArray) To UBound(oArray)
For Each oPara In ActiveDocument.Paragraphs
'Find paragraphs starting with numbers
'Skip if in TOC
If nToc > 0 Then
If
oPara.Range.InRange(ActiveDocument.TablesOfContents(1).Range) = True Then
GoTo SkipPara
End If
'if the ListString is empty, the number is added manually
With oPara
If Left(.Range.Text, Len(oArray(n))) Like oArray(n) = True
Then
If .Range.ListFormat.ListString = "" Then
'Manually numbered - append number to msg - excl.
space or tab
strMsg = strMsg & Trim(Left(.Range.Text,
Len(oArray(n)))) & vbCr
'Mark oPara with red highlight
.Range.HighlightColorIndex = wdRed
End If
End If
End With
SkipPara:
Next oPara
Next n
Application.ScreenUpdating = True
'Show final msg
If strMsg = "" Then
MsgBox "No manually applied numbers were found."
Else
MsgBox "The numbers of the following paragraphs have been manually
applied. The para-graphs have been marked with red highlight:" & vbCr & vbCr
& strMsg
End If
End Sub
--
Regards
Lene Fredborg - Microsoft MVP (Word)
DocTools - Denmarkwww.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
"andreas" wrote:
On Feb 14, 1:55 am, Lene Fredborg <l...@xxxxxxxxxxxxxxxxxxxxxxxxx>
wrote:
The macro below will most likely do most of what you want. However, you may
need to adjust the formatting of numbers to search for and/or add more
variations, e.g. with 2 digits. See the comments in the code. As you will
see, I have created the code so red highlight is applied to the paragraphs
with manually applied numbers. If you don’t want that, delete or comment out
the code line “Range.HighlightColorIndex = wdRed”.
Note that the code does not check the applied style since I imagine that the
manually numbered paragraphs could be formatted with any style (maybe most
likely Normal + direct formatting).
Sub FindAndMarkManuallyNumberedParagraphs()
Dim oPara As Paragraph
Dim strMsg As String
Dim oArray As Variant
Dim n As Long
Application.ScreenUpdating = False
'Create an array of strings to check
'Here only 5 levels in format 1 or 1., 1.1, 1.1.1, 1.1.1.1, 1..1.1..1.1
are included
'Also, the code will not find e.g. 12.11.1 - to do this, include more
variations in the array
oArray = Array("# ", "#" & vbTab, _
"#. ", "#." & vbTab, _
"#.# ", "#.#" & vbTab, _
"#.#.# ", "#.#.#" & vbTab, _
"#.#.#.# ", "#.#.#.#" & vbTab, _
"#.#.#.#.# ", "#.#.#.#.#" & vbTab)
For n = LBound(oArray) To UBound(oArray)
For Each oPara In ActiveDocument.Paragraphs
'Find paragraphs starting with numbers
'if the ListString is empty, the number is added manually
With oPara
If Left(.Range.Text, Len(oArray(n))) Like oArray(n) = True
Then
If .Range.ListFormat.ListString = "" Then
'Manually numbered – append number to msg - excl.
space or tab
strMsg = strMsg & Trim(Left(.Range.Text,
Len(oArray(n)))) & vbCr
'Mark oPara with red highlight
.Range.HighlightColorIndex = wdRed
End If
End If
End With
Next oPara
Next n
Application.ScreenUpdating = True
'Show final msg
If strMsg = "" Then
MsgBox "No manually applied numbers were found."
Else
MsgBox "The numbers of the following paragraphs have been manually
applied. The para-graphs have been marked with red highlight:" & vbCr & vbCr
& strMsg
End If
End Sub
--
Regards
Lene Fredborg - Microsoft MVP (Word)
DocTools - Denmarkwww.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
"andreas" wrote:
Dear Experts:
I got a document where outline numbered built-in headings have been
used in most cases but not always, i.e. sometimes a couple of headings
have been numbered manually such as
2.3 Analysis (outline numbered with built-in heading 2)
2.3.1 In-Depth analysis (manually numbered)
2.3.2 General analysis (manually numbered)
3 Future Outlook (outline numbered with built-in heading 1)
I wonder whether a macro is able ...
.... to loop through all paragraphs starting with a number followed by
a tab stop or spaces followed by words/characters and ...
.... check whether these occurrences have been formatted with the built-
in numbered headings or manually?
In cases where manually formatting has been detected, these
occurrences have to be displayed in a msgbox.
I hope this is not too much to ask / exceeds the scope of this forum.
Help is much appreciated. Thank you very much in advance.
Regards, Andreas- Hide quoted text -
- Show quoted text -
Dear Lene,
thank you so much for your professional help. This is professionalism
at its best. Terrific! It is working as desired. I adapted your code
slightly to include the whole text of the found ranges as well as the
page number of these occurrences.
If .range.ListFormat.ListString = "" Then
strMsg = strMsg & .range.Text & "Page "
& .range.Information(wdActiveEndAdjustedPageNumber) & vbCrLf
There is one small thing I would like to ask you. Your macro also
hilights inserted table of contents. Is it possible to re-write your
code so that the code only loops thru paragraphs starting from the
section with the first occurrence of built-in heading level 1. This
could be section 2 or 3 or any other section number (with the
exception of section 1).
Help is much appreciated. Thank you very much in advance. Regards,
Andreas- Zitierten Text ausblenden -
- Zitierten Text anzeigen -
Dear Lene,
thank you very much for your quick help. I am getting an error message
on line
SkipPara:
Next oPara
.....
Next oPara gets highlighted and it says: Next without for.
It would be fantastic if you could clear this error. Thank you very
much in advance. Regards, Andreas- Hide quoted text -
- Show quoted text -
Hey Lene,
thank you for the tip. This was exactly the case. Again, thank you so
much for your professional help. I really appreciate it.
Kind regards, Andreas
- References:
- Checking whether paragraphs have been formatted with outline numbered headings or manually?
- From: andreas
- RE: Checking whether paragraphs have been formatted with outline numbe
- From: Lene Fredborg
- Re: Checking whether paragraphs have been formatted with outline numbe
- From: andreas
- Re: Checking whether paragraphs have been formatted with outline n
- From: Lene Fredborg
- Re: Checking whether paragraphs have been formatted with outline n
- From: andreas
- Re: Checking whether paragraphs have been formatted with outline n
- From: Lene Fredborg
- Re: Checking whether paragraphs have been formatted with outline n
- From: andreas
- Checking whether paragraphs have been formatted with outline numbered headings or manually?
- Prev by Date: Master Styles
- Next by Date: relative path reference
- Previous by thread: Re: Checking whether paragraphs have been formatted with outline n
- Next by thread: the words "Page Break"
- Index(es):
Relevant Pages
|