Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2006

Tip: Looking for answers? Try searching our database.

How to create a button for inserting bookmark

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mvpreq - 27 Nov 2006 05:54 GMT
I need step wise help for creating a button for inserting bookmark, also
second step is can a code be added to make the bookmark in ascending orders
with each insertion. For example, at first click of the button in the word
document say a "Bookmark1" is inserted and next time at another place in the
document if I need to insert another bookmark on clicking the button it
inserts automatically "Bookmark2" and so on to "Bookmark3...."
Jean-Guy Marcil - 28 Nov 2006 05:14 GMT
mvpreq  was telling us:
mvpreq nous racontait que :

> I need step wise help for creating a button for inserting bookmark,
> also second step is can a code be added to make the bookmark in
[quoted text clipped - 3 lines]
> another bookmark on clicking the button it inserts automatically
> "Bookmark2" and so on to "Bookmark3...."

Try this:

'_______________________________________
Sub InsertMyBookmark()

Const strBookRoot As String = "Bookmark"
Const strBookVar As String = "BookVar"
Dim lngBookNo As Long

'To keep track of the number to use
'Use document variables
'Custom properties could be used as well
With ActiveDocument.Variables
   If .Count = 0 Then
       lngBookNo = 1
   Else
       lngBookNo = CLng(.Item(strBookVar).Value) + 1
   End If
   .Item(strBookVar).Value = lngBookNo
End With

ActiveDocument.Bookmarks.Add strBookRoot & CStr(lngBookNo), _
   Selection.Range

End Sub
'_______________________________________

Two comments:

If the user deletes text that contains bookmarks, you will not end up with a
perfectly numbered scheme. You could have Bookmark1, then Bookmark4,
Bookmark5 and Bookmark9.

Also, there is no guarantee that the location in the document will match the
numbering. You could have Bookmark4 before Bookmark1 to Bookmark3.

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

mvpreq - 28 Nov 2006 06:30 GMT
Thanks Jean-Guy for your prompt response:

I will be able to work on this, on coming weekend and let you know how it
goes. Does this macro includes the sequence for creating a button or it is
only for the numbering scheme.

Deepak
mvpreq - 28 Nov 2006 07:02 GMT
Dear Jean-Guy:

I tried it briefly, it does insert bookmarks in the numbered manner but the
only problem I encountered is that when I tried experimenting by deleting
some bookmark it causes the "Word" to close with an error reporting screen.
Also please guide me how to make a button on the tool bar for this Macro
without each time going to Tool-Macros-Choosing Macro and choosing run.

Thanks for your time

Deepak
Jean-Guy Marcil - 28 Nov 2006 17:00 GMT
mvpreq  was telling us:
mvpreq nous racontait que :

> Dear Jean-Guy:
>
> I tried it briefly, it does insert bookmarks in the numbered manner
> but the only problem I encountered is that when I tried experimenting
> by deleting some bookmark it causes the "Word" to close with an error

I doubt this has anything to do with the macro I posted.

Can post the exact steps you took that made your Word crash?
What Word version?

> reporting screen. Also please guide me how to make a button on the
> tool bar for this Macro without each time going to
> Tool-Macros-Choosing Macro and choosing run.

Use the information at
   http://word.mvps.org/FAQs/Customization/AsgnCmdOrMacroToToolbar.htm
to either create a toolbar or simply add a button to an existing toolbar.

You also have to think about the storage... do you want this button
available to all Word documents or only those created from a particular
template?
If it is the latter, then add the code and the button to that template.

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.