Re: Endnotes and formatted text by daswifty
daswifty
Mon Mar 03 07:27:01 PST 2008
Thanks Doug, but this macro doesn't help me with much. All it appears to do
(at least on Word 2007) is convert all of the Endnotes text to regular text
and change the references to superscript.
I need something to go the other way. To convert/copy/insert regular text
into the endnote text section as formatted text.
"Doug Robbins - Word MVP" wrote:
> There may be something in the following code that will help you:
>
> ' Macro created 29/09/99 by Doug Robbins to replace endnotes with textnotes
> at end of document
>
> ' to replace the endnote reference in the body of the document with a
> superscript number.
>
> '
>
> Dim aendnote As Endnote
>
> For Each aendnote In ActiveDocument.Endnotes
>
> ActiveDocument.Range.InsertAfter vbCr & aendnote.Index & vbTab &
> aendnote.Range
>
> aendnote.Reference.InsertBefore "a" & aendnote.Index & "a"
>
> Next aendnote
>
> For Each aendnote In ActiveDocument.Endnotes
>
> aendnote.Reference.Delete
>
> Next aendnote
>
> Selection.Find.ClearFormatting
>
> Selection.Find.Replacement.ClearFormatting
>
> With Selection.Find.Replacement.Font
>
> .Superscript = True
>
> End With
>
> With Selection.Find
>
> .Text = "(a)([0-9]{1,})(a)"
>
> .Replacement.Text = "\2"
>
> .Forward = True
>
> .Wrap = wdFindContinue
>
> .Format = True
>
> .MatchWildcards = True
>
> End With
>
> Selection.Find.Execute Replace:=wdReplaceAll
>
>
> --
> 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
>
> "daswifty" <daswifty@discussions.microsoft.com> wrote in message
> news:8FD20C53-A700-4CD7-90A2-862671E7D8F2@microsoft.com...
> > Hi, I am trying to create a Word C# add-in that will find all of the
> > endnotes
> > in a document, re-sort them so that the first one will be #1, and add a
> > hyperlink back to the section heading that the endnote reference resides
> > in.
> >
> > Most everything is working well except I can't do two things:
> > 1) Add formatted text programmatically to the endnote text. Endnotes.Add
> > doesn't allow a range (just text) and when I try to update the endnote
> > after
> > adding a temporary text string, the resulting endnote text is blank:
> > Range = aDoc.Range(ref textStart, ref textEnd);
> > aDoc.Endnotes[1].Range = findE;
> >
> > 2) Add the hyperlink back to the section heading. This is most likely due
> > to
> > my issue with the formatted text, but I have tried to work around it by
> > using
> > a Find and trying to find the Endnote Text, but that isn't working either.
> > Are we not able to find Endnote Text programmatically? I tried a VBA macro
> > as
> > well and it didn't work. Here is my C# approach:
> > Range findEndnote = aDoc.Content;
> > findEndnote.Find.Forward = true;
> > object objTrue = true;
> > object objEndnoteStyle = "Endnote Text";
> > object objEndnoteFind = aDoc.Styles.get_Item(ref objEndnoteStyle);
> > findEndnote.Find.set_Style(ref objEndnoteFind);
> > findEndnote.Find.Text = "Section";
> > findEndnote.Find.Execute(
> > ref missing, ref missing, ref missing, ref missing, ref missing,
> > ref missing, ref missing, ref missing, ref objTrue, ref missing,
> > ref missing, ref missing, ref missing, ref missing, ref missing);
> >
>
>
>