Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 09-25-2023, 11:19 PM
Hmelk Hmelk is offline Runtime error 5828, invalid bookmark name - hyperlink page number index Windows 10 Runtime error 5828, invalid bookmark name - hyperlink page number index Office 2016
Novice
Runtime error 5828, invalid bookmark name - hyperlink page number index
 
Join Date: Sep 2023
Posts: 6
Hmelk is on a distinguished road
Question Runtime error 5828, invalid bookmark name - hyperlink page number index

Split from this thread. (Code from macropod)
Quote:
Code:
Sub IndexHyperlinker()
Application.ScreenUpdating = False
Dim Fld As Field, Rng As Range, StrIdx As String, StrList As String, i As Long, j As Long
StrList = vbCr
With ActiveDocument
  .Fields.Update
  For Each Fld In .Fields
    With Fld
      If .Type = wdFieldIndexEntry Then
        StrIdx = Trim(Replace(Replace(Split(.Code.Text, "XE ")(1), ", ", "_"), Chr(34), ""))
        If InStr(StrList, vbCr & StrIdx & ",") = 0 Then
          i = 0
          StrList = StrList & StrIdx & "," & i & vbCr
        Else
          i = Split(Split(StrList, vbCr & StrIdx & ",")(1), vbCr)(0)
        End If
          StrList = Replace(StrList, StrIdx & "," & i & vbCr, StrIdx & "," & i + 1 & vbCr)
          i = i + 1
        Set Rng = .Code
        With Rng
          .Start = .Start - 1
          .End = .End + 1
          .Bookmarks.Add Name:=StrIdx & i, Range:=.Duplicate
        End With
      End If
    End With
  Next
  Set Rng = .Indexes(1).Range
  With Rng
    .Fields(1).Unlink
    If Asc(.Characters.First) = 12 Then .Start = .Start + 1
    For i = 1 To .Paragraphs.Count
      With .Paragraphs(i).Range
        StrIdx = Replace(Split(.Text, vbTab)(0), ", ", "_")
        .MoveStartUntil vbTab, wdForward
        .Start = .Start + 1
        .End = .End - 1
        For j = 1 To .Words.Count
          If IsNumeric(Trim(.Words(j).Text)) Then
            .Hyperlinks.Add Anchor:=.Words(j), SubAddress:=GetBkMk(Trim(.Words(j).Text), StrIdx), TextToDisplay:=.Words(j).Text
          End If
        Next
      End With
    Next
  End With
End With
Application.ScreenUpdating = True
End Sub

Function GetBkMk(j As Long, StrIdx As String) As String
Dim i As Long
With ActiveDocument
  For i = 1 To .Bookmarks.Count
    If InStr(.Bookmarks(i).Name, StrIdx) = 1 Then
      If .Bookmarks(i).Range.Information(wdActiveEndAdjustedPageNumber) = j Then
        GetBkMk = .Bookmarks(i).Name: Exit For
      End If
    End If
  Next
End With
End Function
Hello,


I have started the macro and get the error message "Runtime error 5828, invalid bookmark name. In the debugger it looks like this: .Bookmarks.Add Name:=StrIdx & i, Range:=.Duplicate
Unfortunately I have no idea about VBL, can someone help me?
I am working with Word 365.

Thanxs



Hmelk

Last edited by Charles Kenyon; 09-26-2023 at 11:41 AM.
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Runtime error 5828, invalid bookmark name - hyperlink page number index How to hyperlink an index entry to a bookmark in a document? Ashok P Word VBA 2 02-28-2021 03:18 PM
Runtime error 5828, invalid bookmark name - hyperlink page number index Can I use a variable to display the page number of a bookmark ? delboy Word 3 12-29-2020 01:16 PM
Runtime error 5828, invalid bookmark name - hyperlink page number index use hyperlink in page number in index boywonder Word 2 07-27-2017 03:18 PM
Runtime error 5487 - Word cannot complete the save to to file permission error franferns Word 0 11-25-2009 05:35 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:15 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft