Solved

Runtime error 5678 Word cannot find the requested bookmark

Posted on 2008-06-24
2
1,483 Views
Last Modified: 2010-04-21
Hi,
I have a Macro that is finding a value of a bookmark in the body of a document and I am then changing another value of a bookmark in the header accordingly.
This works fine while destination bookmark is in the body of the document but has the above error if I move the destination bookmark to the header.
Using a recorded macro has the same problem.
It seems even though you are in the header when you run the macro it reverts to only looking at the body.

Can anyone explain why this is? and or give me a solution to the problem.
I see this is close, but having an input box isn't what I have and I don't know the piece I need to add to my code to make it work...

http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Word/Q_22960647.html

Thanks Tony
Dim lngValue As Long
 

'Selection.GoTo What:=wdGoToBookmark, Name:="RM0TotalInclGST"

    Selection.GoTo What:=wdGoToBookmark, Name:="RM0TotalInclGST"

    With ActiveDocument.Bookmarks

        .DefaultSorting = wdSortByName

        .ShowHidden = False

    End With

Selection.MoveRight Unit:=wdCharacter, Count:=2, Extend:=wdExtend

lngValue = Selection.Text
 

Selection.GoTo What:=wdGoToBookmark, Name:="INVOICETYPE"
 

If Val(lngValue) < 0 Then

Selection.Text = "CREDIT NOTE"
 

Else

Selection.Text = "TAX INVOICE"

End If
 

End Sub

Open in new window

0
Comment
Question by:Tony303
2 Comments
 
LVL 23

Accepted Solution

by:
irudyk earned 500 total points
ID: 21929295
Try the following revised code:
Dim lngValue As Long

 

'Selection.GoTo What:=wdGoToBookmark, Name:="RM0TotalInclGST"

    Selection.GoTo What:=wdGoToBookmark, Name:="RM0TotalInclGST"

    With ActiveDocument.Bookmarks

        .DefaultSorting = wdSortByName

        .ShowHidden = False

    End With

Selection.MoveRight Unit:=wdCharacter, Count:=2, Extend:=wdExtend

lngValue = Selection.Text

 

'Selection.GoTo What:=wdGoToBookmark, Name:="INVOICETYPE"

ActiveDocument.Bookmarks("INVOICETYPE").Select

 

If Val(lngValue) < 0 Then

Selection.Text = "CREDIT NOTE"

 

Else

Selection.Text = "TAX INVOICE"

End If
 

ActiveWindow.ActivePane.Close

 

End Sub

Open in new window

0
 
LVL 12

Author Closing Comment

by:Tony303
ID: 31470457
Hi,
Sorry for the long wait on this one, I guess my spam mail trapped the solution.
Anyway, great thanks, I see the secret is the
ActiveDocument.Bookmarks("INVOICETYPE").Select
and
ActiveWindow.ActivePane.Close

Thanks again

Tony
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If you work with Word a lot, you probably use styles. If you use styles a lot, you've probably balled your fist more often than not when working with the ribbon. In Word 2007/2010, one of the things that I find missing when using styles is a quic…
Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now