Cross Reference Macro to Current Paragraph

K

Kurtis

I am having a problem with a cross reference and would really appreciate some
help. What I am trying to do is create a macro that will insert a full
context cross reference that references the current paragraph. For instance,
par. 3.5 states "except as provided on Schedule 3.5. Here is my code so far:

Selection.InsertCrossReference ReferenceType:="Numbered item", _
ReferenceKind:=wdNumberFullContext, ReferenceItem:="?",
InsertAsHyperlink _
:=True, IncludePosition:=False
End Sub

Any help on this would be greatly appreciated.
 
M

macropod

Hi Kurtis,

The ReferenceItem will be a bookmark - either one you've created or one that
Word has created and for which you know the ID/Name.

Cheers
 
K

Kurtis

Thanks for your response. That makes sense, but how do I automate the
process? How can I make it reflect the correct paragraph context each time
the macro is run?

macropod said:
Hi Kurtis,

The ReferenceItem will be a bookmark - either one you've created or one that
Word has created and for which you know the ID/Name.

Cheers

--
macropod
[MVP - Microsoft Word]


Kurtis said:
I am having a problem with a cross reference and would really appreciate some
help. What I am trying to do is create a macro that will insert a full
context cross reference that references the current paragraph. For instance,
par. 3.5 states "except as provided on Schedule 3.5. Here is my code so far:

Selection.InsertCrossReference ReferenceType:="Numbered item", _
ReferenceKind:=wdNumberFullContext, ReferenceItem:="?",
InsertAsHyperlink _
:=True, IncludePosition:=False
End Sub

Any help on this would be greatly appreciated.
 
K

Kurtis

Here is the new code:

With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="b"
.DefaultSorting = wdSortByLocation
.ShowHidden = True
End With
Selection.InsertCrossReference ReferenceType:="Bookmark",
ReferenceKind:= _
wdNumberFullContext, ReferenceItem:="b", InsertAsHyperlink:=True, _
IncludePosition:=False
End Sub

Is there a way to generate a new bookmark Name (in this case "b") and copy
it to the ReferenceItem (b) each time the macro is run?

Kurtis said:
Thanks for your response. That makes sense, but how do I automate the
process? How can I make it reflect the correct paragraph context each time
the macro is run?

macropod said:
Hi Kurtis,

The ReferenceItem will be a bookmark - either one you've created or one that
Word has created and for which you know the ID/Name.

Cheers

--
macropod
[MVP - Microsoft Word]


Kurtis said:
I am having a problem with a cross reference and would really appreciate some
help. What I am trying to do is create a macro that will insert a full
context cross reference that references the current paragraph. For instance,
par. 3.5 states "except as provided on Schedule 3.5. Here is my code so far:

Selection.InsertCrossReference ReferenceType:="Numbered item", _
ReferenceKind:=wdNumberFullContext, ReferenceItem:="?",
InsertAsHyperlink _
:=True, IncludePosition:=False
End Sub

Any help on this would be greatly appreciated.
 
R

Russ

Kurtis,

You could try:
Dim n as Long
Dim myBookmark as String

n = ActiveDocument.Bookmarks.Count + 1
myBookmark = "b" & Cstr(n)

Then replace "b" in your code below with the variable myBookmark, verbatim
(without quotation marks), in both places.
Here is the new code:

With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="b"
.DefaultSorting = wdSortByLocation
.ShowHidden = True
End With
Selection.InsertCrossReference ReferenceType:="Bookmark",
ReferenceKind:= _
wdNumberFullContext, ReferenceItem:="b", InsertAsHyperlink:=True, _
IncludePosition:=False
End Sub

Is there a way to generate a new bookmark Name (in this case "b") and copy
it to the ReferenceItem (b) each time the macro is run?

Kurtis said:
Thanks for your response. That makes sense, but how do I automate the
process? How can I make it reflect the correct paragraph context each time
the macro is run?

macropod said:
Hi Kurtis,

The ReferenceItem will be a bookmark - either one you've created or one that
Word has created and for which you know the ID/Name.

Cheers

--
macropod
[MVP - Microsoft Word]


I am having a problem with a cross reference and would really appreciate
some
help. What I am trying to do is create a macro that will insert a full
context cross reference that references the current paragraph. For
instance,
par. 3.5 states "except as provided on Schedule 3.5. Here is my code so
far:

Selection.InsertCrossReference ReferenceType:="Numbered item", _
ReferenceKind:=wdNumberFullContext, ReferenceItem:="?",
InsertAsHyperlink _
:=True, IncludePosition:=False
End Sub

Any help on this would be greatly appreciated.
 
H

Helmut Weber

Hi Kurtis

as far as I see, you are inserting a crossreference
to a bookmark in the bookmark [] or adjacent ][ to it.

Doesn't make sense to me.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
K

Kurtis

Russ, that worked! Thank you very much for helping me about.

Russ said:
Kurtis,

You could try:
Dim n as Long
Dim myBookmark as String

n = ActiveDocument.Bookmarks.Count + 1
myBookmark = "b" & Cstr(n)

Then replace "b" in your code below with the variable myBookmark, verbatim
(without quotation marks), in both places.
Here is the new code:

With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="b"
.DefaultSorting = wdSortByLocation
.ShowHidden = True
End With
Selection.InsertCrossReference ReferenceType:="Bookmark",
ReferenceKind:= _
wdNumberFullContext, ReferenceItem:="b", InsertAsHyperlink:=True, _
IncludePosition:=False
End Sub

Is there a way to generate a new bookmark Name (in this case "b") and copy
it to the ReferenceItem (b) each time the macro is run?

Kurtis said:
Thanks for your response. That makes sense, but how do I automate the
process? How can I make it reflect the correct paragraph context each time
the macro is run?

:

Hi Kurtis,

The ReferenceItem will be a bookmark - either one you've created or one that
Word has created and for which you know the ID/Name.

Cheers

--
macropod
[MVP - Microsoft Word]


I am having a problem with a cross reference and would really appreciate
some
help. What I am trying to do is create a macro that will insert a full
context cross reference that references the current paragraph. For
instance,
par. 3.5 states "except as provided on Schedule 3.5. Here is my code so
far:

Selection.InsertCrossReference ReferenceType:="Numbered item", _
ReferenceKind:=wdNumberFullContext, ReferenceItem:="?",
InsertAsHyperlink _
:=True, IncludePosition:=False
End Sub

Any help on this would be greatly appreciated.
 
M

Mickey

I know I'm getting into this late but could this code be modified to create a
cross reference based on existing bookmarks in the document. The situation
is this....I have multiple headers in a document due to portrait and
landscape pages. There are 4 bookmarks in the header (DOC_NAME, DOC_VERSION,
DOC_TITLE, DOC_SITE). The headers each need the same bookmarks. I have a
macro to add the bookmarks but the bookmarks are only retained in the last
header. I'm wondering if I can search the headers where the bookmark was
lost and include cross reference code. For example, search for "[DOC_NAME]
and have code that cross references it to the bookmark DOC_NAME.

Any help is very much appreciated.

Thanks,
Mickey

Russ said:
Kurtis,

You could try:
Dim n as Long
Dim myBookmark as String

n = ActiveDocument.Bookmarks.Count + 1
myBookmark = "b" & Cstr(n)

Then replace "b" in your code below with the variable myBookmark, verbatim
(without quotation marks), in both places.
Here is the new code:

With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="b"
.DefaultSorting = wdSortByLocation
.ShowHidden = True
End With
Selection.InsertCrossReference ReferenceType:="Bookmark",
ReferenceKind:= _
wdNumberFullContext, ReferenceItem:="b", InsertAsHyperlink:=True, _
IncludePosition:=False
End Sub

Is there a way to generate a new bookmark Name (in this case "b") and copy
it to the ReferenceItem (b) each time the macro is run?

Kurtis said:
Thanks for your response. That makes sense, but how do I automate the
process? How can I make it reflect the correct paragraph context each time
the macro is run?

:

Hi Kurtis,

The ReferenceItem will be a bookmark - either one you've created or one that
Word has created and for which you know the ID/Name.

Cheers

--
macropod
[MVP - Microsoft Word]


I am having a problem with a cross reference and would really appreciate
some
help. What I am trying to do is create a macro that will insert a full
context cross reference that references the current paragraph. For
instance,
par. 3.5 states "except as provided on Schedule 3.5. Here is my code so
far:

Selection.InsertCrossReference ReferenceType:="Numbered item", _
ReferenceKind:=wdNumberFullContext, ReferenceItem:="?",
InsertAsHyperlink _
:=True, IncludePosition:=False
End Sub

Any help on this would be greatly appreciated.
 
R

Russ

Mickey,
I think your question was answered by Tony in the other thread:
"Retaining Bookmarks in Autotext Macros"

I know I'm getting into this late but could this code be modified to create a
cross reference based on existing bookmarks in the document. The situation
is this....I have multiple headers in a document due to portrait and
landscape pages. There are 4 bookmarks in the header (DOC_NAME, DOC_VERSION,
DOC_TITLE, DOC_SITE). The headers each need the same bookmarks. I have a
macro to add the bookmarks but the bookmarks are only retained in the last
header. I'm wondering if I can search the headers where the bookmark was
lost and include cross reference code. For example, search for "[DOC_NAME]
and have code that cross references it to the bookmark DOC_NAME.

Any help is very much appreciated.

Thanks,
Mickey

Russ said:
Kurtis,

You could try:
Dim n as Long
Dim myBookmark as String

n = ActiveDocument.Bookmarks.Count + 1
myBookmark = "b" & Cstr(n)

Then replace "b" in your code below with the variable myBookmark, verbatim
(without quotation marks), in both places.
Here is the new code:

With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="b"
.DefaultSorting = wdSortByLocation
.ShowHidden = True
End With
Selection.InsertCrossReference ReferenceType:="Bookmark",
ReferenceKind:= _
wdNumberFullContext, ReferenceItem:="b", InsertAsHyperlink:=True, _
IncludePosition:=False
End Sub

Is there a way to generate a new bookmark Name (in this case "b") and copy
it to the ReferenceItem (b) each time the macro is run?

:

Thanks for your response. That makes sense, but how do I automate the
process? How can I make it reflect the correct paragraph context each time
the macro is run?

:

Hi Kurtis,

The ReferenceItem will be a bookmark - either one you've created or one
that
Word has created and for which you know the ID/Name.

Cheers

--
macropod
[MVP - Microsoft Word]


I am having a problem with a cross reference and would really appreciate
some
help. What I am trying to do is create a macro that will insert a full
context cross reference that references the current paragraph. For
instance,
par. 3.5 states "except as provided on Schedule 3.5. Here is my code so
far:

Selection.InsertCrossReference ReferenceType:="Numbered item", _
ReferenceKind:=wdNumberFullContext, ReferenceItem:="?",
InsertAsHyperlink _
:=True, IncludePosition:=False
End Sub

Any help on this would be greatly appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top