From: Rathish on
Kindly help

I have a long document and I need to show a hyperlink as 'Back to Table of
Contents' at the top from the 3rd page onwards. To resolve it I have created
a macro which will insert the hyperlink on each page.

The problem that i am facing is that at many times whenever i run this macro
the hyperlinks gets pasted one after the other instead of one in each page.
codes are given below.

Sub test()
Dim s As Shape
Dim alt_text As String
Dim page_num As Integer
Dim counter As Integer
Dim i As Integer


counter = 1



For Each s In ActiveDocument.Shapes
alt_text = s.AlternativeText
If alt_text = "Pict" Then
counter = counter + 1
If InStr(1, alt_text, "Pict", vbTextCompare) > 0 Then
s.Select
Selection.ShapeRange.Select
Selection.Copy
Selection.ShapeRange.LockAnchor = False
Selection.ShapeRange.LayoutInCell = True
End If
End If
Next s


page_num = ActiveDocument.BuiltInDocumentProperties(wdPropertyPages)


For i = 4 To page_num

' Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:=CStr(i)
Selection.GoTo What:=wdGoToPage, Which:=wdGoToAbsolute, Count:=i
Selection.Paste
Selection.ShapeRange.RelativeHorizontalPosition = _
wdRelativeHorizontalPositionColumn
Selection.ShapeRange.RelativeVerticalPosition = _
wdRelativeVerticalPositionPage
Selection.ShapeRange.Left = InchesToPoints(5.55)
Selection.ShapeRange.Top = InchesToPoints(-0.27)
Selection.ShapeRange.LockAnchor = False
Selection.ShapeRange.LayoutInCell = True

Next i

End Sub

Thanks & Regards
Radish Kumar


--
Thanks & Regards
Rathish
From: PJY on
Why don't you just use a "place in this document" hyperlink?

"Rathish" wrote:

> Kindly help
>
> I have a long document and I need to show a hyperlink as 'Back to Table of
> Contents' at the top from the 3rd page onwards. To resolve it I have created
> a macro which will insert the hyperlink on each page.
>
> The problem that i am facing is that at many times whenever i run this macro
> the hyperlinks gets pasted one after the other instead of one in each page.
> codes are given below.
>
> Sub test()
> Dim s As Shape
> Dim alt_text As String
> Dim page_num As Integer
> Dim counter As Integer
> Dim i As Integer
>
>
> counter = 1
>
>
>
> For Each s In ActiveDocument.Shapes
> alt_text = s.AlternativeText
> If alt_text = "Pict" Then
> counter = counter + 1
> If InStr(1, alt_text, "Pict", vbTextCompare) > 0 Then
> s.Select
> Selection.ShapeRange.Select
> Selection.Copy
> Selection.ShapeRange.LockAnchor = False
> Selection.ShapeRange.LayoutInCell = True
> End If
> End If
> Next s
>
>
> page_num = ActiveDocument.BuiltInDocumentProperties(wdPropertyPages)
>
>
> For i = 4 To page_num
>
> ' Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:=CStr(i)
> Selection.GoTo What:=wdGoToPage, Which:=wdGoToAbsolute, Count:=i
> Selection.Paste
> Selection.ShapeRange.RelativeHorizontalPosition = _
> wdRelativeHorizontalPositionColumn
> Selection.ShapeRange.RelativeVerticalPosition = _
> wdRelativeVerticalPositionPage
> Selection.ShapeRange.Left = InchesToPoints(5.55)
> Selection.ShapeRange.Top = InchesToPoints(-0.27)
> Selection.ShapeRange.LockAnchor = False
> Selection.ShapeRange.LayoutInCell = True
>
> Next i
>
> End Sub
>
> Thanks & Regards
> Radish Kumar
>
>
> --
> Thanks & Regards
> Rathish