
Signature
Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID
Russ,
the documents in which I want to run code are generated by third parties and
could be whatever they use. Typically they use automatic heading numbering,
and often use heading numbering for text as well (ie to get legal numbered
paragraphs). See examples below.
ie typical situation 1:
1.2 Heading level 2
1.2.1 Heading level 3
1.2.1.1 Text para 1, but numbered as an outline level
1.2.1.2 Text para 2, but numbered as an outline level **example comment **
1.2.1.3 Text para 3, but numbered as an outline level
Perhaps unnumbered text or figure may be interspersed.
1.2.1.4 Text para 4, but numbered as an outline level
ie typical situation 2:
1.2 Heading level 2
1.2.1 Heading level 3
Text para 1 unnumbered
Text para 2 unnumbered **example comment **
Text para 3 unnumbered
Perhaps a figure may be interspersed.
Text para 4 unnumbered
These documents may be delivered to us (the customer) and we often generate
comments in Word. However, comments are stored on a separate database and
come from many sources, but are expected in a standard format that references
the paragraph (among other things) in the document. I have generated code to
visit each comment and extract some of the necessary data (eg page number,
comment details, contextual text) but am trying to extract the paragraph
number. My ideas to do this so far are to:
A. If the current para is an outline level:
(i) Copy the para and paste as unformatted text into a new window. I note
that this converts the para number into text. Grab the first numbers in this
new buffer as the para number (probably up to a tab which seems to follow).
(ii) use this number as a reference. In situation 1 above returns "1.2.1.2"
B. If the current para is not outline level:
(i) move to the first previous para that is an outline level
(ii) count the paras to the previous outline
(iii) now get the para number as for A.
(iv) provide the count of paras from the previous outline and the previous
outline number as a reference. In situation 2 above returns "1.2.1.1
paragraph 2"
Given that when Word pastes the heading text as unformatted text into
another buffer it knows the para number, I thought that there should be some
easier way to get hold of it....
I'd just like to say that your suggestion in your post re extracting the
number at the start of a para started me down this direction of thinking...
any improvements on my ideas are most welcome :)
cheers, dg
> Dave,
> Could you give an example of what you see now? And an example of what you
[quoted text clipped - 61 lines]
> >>>> the
> >>>> numbers as Word may have to do.
Dave Gapp - 19 Aug 2007 13:24 GMT
After a bit of digging, I found out how to get to the clipboard (see code
below, which simplifies things as I don't need to open another doc to paste
text into...
This bit of code works fine to get the heading number of the start of the
selection
Dim s As String
Selection.Collapse (wdCollapseStart)
Selection.MoveStart Unit:=wdParagraph, Count:=-1
Selection.MoveEnd Unit:=wdParagraph, Count:=1
Selection.Copy
s = GetOffClipboard()
s = Left(s, InStr(s, Chr$(vbKeyTab)))
MsgBox (s)
Public Function GetOffClipboard() As Variant
'
' From http://www.cpearson.com/excel/clipboard.htm
' needs to ensure Tools/References enables the Microsoft Forms 2.0 Library
' which lives in Fm20.dll under C:\WINDOWS\system32
'
Dim MyDataObj As New DataObject
MyDataObj.GetFromClipboard
GetOffClipboard = MyDataObj.GetText()
End Function
> Russ,
> the documents in which I want to run code are generated by third parties and
[quoted text clipped - 118 lines]
> > >>>> the
> > >>>> numbers as Word may have to do.