Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #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
  #2  
Old 09-26-2023, 11:43 AM
Charles Kenyon Charles Kenyon is online now Runtime error 5828, invalid bookmark name - hyperlink page number index Windows 11 Runtime error 5828, invalid bookmark name - hyperlink page number index Office 2021
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,140
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

I've split your question into a new (unsolved) thread in the vba forum so that it can get better attention.
Reply With Quote
  #3  
Old 09-26-2023, 08:59 PM
Guessed's Avatar
Guessed Guessed 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
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

There are rules for valid characters for bookmark names and it appears your code is trying create a bookmark with a name that is considered invalid. From memory, bookmarks can't start with a number, nor can they contain a space for instance. There are probably other rules on what is allowed as a bookmark name.

When you encounter the error and choose to Debug, hover over the StrIdx to see its value and make note of what it says. Do any characters appear to be unacceptable as bookmark names?
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #4  
Old 09-27-2023, 04:53 AM
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
Default

Thanks for the tip, I found something out. It works when the displayed text is the same as the highlighted text.
"House=house" works,
"house=house, old" does not work.


How to change this?


Thanxs Hmelk
Reply With Quote
  #5  
Old 09-29-2023, 12:59 AM
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
Default

Hello,

there must not be any spaces, (),* in the index word. But underscores_are.
If I do it like this: A_house = Build_a_house
Then it works.
Later replace the _ with spaces in the HTML index and it looks OK again.
Maybe it's not such an elegant solution, but it seems to work.


Hmelk
Reply With Quote
  #6  
Old 10-14-2023, 03:40 AM
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
Default

Hello,
now this error message appears.
Does anyone have any idea what I am doing this wrong?


Runtimeerror 4120, Wrong Papameter

.Hyperlinks.Add Anchor:=.Words(j), SubAddress:=GetBkMk(Trim(.Words(j).Text), StrIdx), TextToDisplay:=.Words(j).Text


Thanks



Hmelk
Reply With Quote
  #7  
Old 10-14-2023, 10:41 AM
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
Default

Hello,

I have found the problem, I mean. I had created the markers automatically via a Word file. This also entered markers in the footnotes index. When I deleted those, I got an index with hyperlink. I will test this further tomorrow.




Hmelk
Reply With Quote
Reply



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 03:11 PM.


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