From: Rathish on 30 Mar 2010 10:49 I am new to word macros. I need help urgently. I have a long document and 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. (Code given below) The problem that i am facing is that at many times whenever i run this macro the hyperlinks gets pasted one after the other on the first page instead of one in each page. 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 If possible please help me out. -- Thanks & Regards Rathish
|
Pages: 1 Prev: CustomUI code disappears, if any textbox is deleted from the d Next: Pasting a picture |