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 / July 2007

Tip: Looking for answers? Try searching our database.

Bookmarks

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Francis Hookham - 17 Jun 2007 10:40 GMT
(I thought I sent ths yeaterday but cannot find it!)

The sub below works well being run from a button on a toolbar.

It would be nice to cut out the InputBox and instead select the text and let
the macro copy that, remove white space and use that as the BookmarkName.

I have tried a couple of times but am missing something - brains probably!

Thanks

Francis Hookham

Sub SetBookmarks()
BookmarkName = InputBox("Bookmark name?")
   With ActiveDocument.Bookmarks
       .Add Range:=Selection.Range, Name:=BookmarkName
       .DefaultSorting = wdSortByName
       .ShowHidden = False
   End With
   Windows("Club Officers 07-08.doc").Activate
End Sub
Doug Robbins - Word MVP - 17 Jun 2007 11:01 GMT
Use:

With ActiveDocument.Bookmarks
   .Add Range:=Selection.Range, Name:=Replace(Selection.Range.Text, " ",
"")
   .DefaultSorting = wdSortByName
   .ShowHidden = False
End With

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> (I thought I sent ths yeaterday but cannot find it!)
>
[quoted text clipped - 19 lines]
>    Windows("Club Officers 07-08.doc").Activate
> End Sub
Francis Hookham - 17 Jun 2007 19:39 GMT
Great - thanks Doug.

Any ideas for a refinement to help with the following problem - my main use
for this will be to select a heading and use that as the bookmark. I get a
error message with this macro because it cannot cope with the hiden
paragraph mark at the end of the selection. Shift selecting does not help
because that does not eleiminate the paragraph mark. Ok, I do not have to
use all words in the heading but many are single words.

Anyway of removing the hidden paragraph mark (if there is one!)?

Francis

> Use:
>
[quoted text clipped - 29 lines]
>>    Windows("Club Officers 07-08.doc").Activate
>> End Sub
Russ - 17 Jun 2007 22:57 GMT
Francis,
Will this work for you?

Dim myRange as Range
Set myRange = Selection.Range
If Selection.Characters.Last = vbCr Then
    myRange.End = myRange.End - 1
End If
With ActiveDocument.Bookmarks
   .Add Range:=myRange, Name:=Replace(myRange.Text, " ",
"")
   .DefaultSorting = wdSortByName
   .ShowHidden = False
End With

You could use Name:=Trim(myRange.Text) to get rid of just leading and
trailing spaces.

>> With ActiveDocument.Bookmarks
>>    .Add Range:=Selection.Range, Name:=Replace(Selection.Range.Text, " ",
>> "")
>>    .DefaultSorting = wdSortByName
>>    .ShowHidden = False
>> End With

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

Russ - 17 Jun 2007 23:18 GMT
Francis,
Two other observations:
1. You could write a macro to bookmark all headings of a particular style.
2. When you use headings with the styles Heading 1, 2... ,
You can view and edit the document in Outline mode and easily collapse and
expand parts of the document, without the need for creating bookmarks.
Type outline in Word help.

> Francis,
> Will this work for you?
[quoted text clipped - 20 lines]
>>>    .ShowHidden = False
>>> End With

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

Russ - 17 Jun 2007 23:31 GMT
Hi again Francis,
A third thing is create a TOC

Definition from Word help:
table of contents
A list of the specific headings in a document, along with the page numbers
they appear on.

When you click on a page number in a TOC, you are taken to that page.

> Francis,
> Two other observations:
[quoted text clipped - 28 lines]
>>>>    .ShowHidden = False
>>>> End With

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

Francis Hookham - 18 Jun 2007 09:53 GMT
Thanks Russ three times - no time yet to take up your helpful comments - it
is all to do with converting a club bulletin written in Word, with TOC, for
a web page and I am feeling my way on that - the TOC works on Heading 1
which I have cut and pasted back as text and removed the tab and page number
(which would not apply on the webpage). Maybe I going at it the hard way and
so will try positing in the bulletin as it stands and adjusting it there but
I am new enough at it to find HTML a bit daunting.

My main problem is I love the challenge of writing a good macro so I
automatically take that route! At my age I ought to know better.

Many thanks - I'll report back in a few days - if I don't get distracted by
another query 'Running macros' I posted late yesterday and I see Jay
Freedman has answered - what a fantastic resource this is thanks to people
like you and him.

Francis

> Hi again Francis,
> A third thing is create a TOC
[quoted text clipped - 41 lines]
>>>>>    .ShowHidden = False
>>>>> End With
Francis Hookham - 28 Jun 2007 12:42 GMT
Back again without success - it's more of a challenge than a need since the
TOC way pretty well does what I want but there are times when I should like
to set up bookmarks This is how I intrepreted the suggestion you made in
this posting but I cannot see why it is not working. All a bit above my
head. Any suggestions please Russ:

Sub SetBookmarks()

Dim myBookmarkRange As Range
Set myBookmarkRange = Selection.Range
If Selection.Characters.Last = vbCr Then
    myBookmarkRange.End = myBookmarkRange.End - 1
End If

With ActiveDocument.Bookmarks
   .Add Range:=myBookmarkRange, Name:=Replace(myBookmarkRange.Text, " ",
"")
   .DefaultSorting = wdSortByName
   .ShowHidden = False
End With

With ActiveDocument.Bookmarks
   .Add Range:=Selection.Range, Name:=Trim(myBookmarkRange.Text)
   .DefaultSorting = wdSortByName
   .ShowHidden = False
End With

End Sub

> Francis,
> Two other observations:
[quoted text clipped - 29 lines]
>>>>    .ShowHidden = False
>>>> End With
Russ - 29 Jun 2007 07:50 GMT
Francis,
Showing the code is a good idea, but you also neglected to say on which line
you are having an error and what is the error message.
I suspect the problem is that your code is .add ing the same bookmark you
just created or there is punctuation in the selection. In other words, each
time you use the .add method, it is attempting to add a bookmark.
If you a trying to get rid of all the space characters in the selection to
create a bookmark name of the selection,
then trim and replace outside of the .add method
or do both those operations inside **one** .add method.

You can 'nest' functions within each other.

There might be some limit on how long your bookmark name may be. But on the
outer part of the 'nest' you could use the Left() function to create a name
of only so many characters.

Use one .add line:
.Add Range:=myBookmarkRange, Name:=Left(Trim(Replace( _
   myBookmarkRange.Text, " ", "_")), 15)

Be aware, selecting anything with punctuation ( other than underscores )
will cause an bookmark name error.

Rather than self-generating a bookmark name, it might be better to pop up an
inputbox to ask for a bookmark name. You could have the default text be part
of the selection, which you could edit to make a legitimate bookmark name.

Dim BookmarkName As String
BookmarkName = InputBox("Bookmark Name Suggestion:" & vbCr _
   & "Delete any punctuation!" & vbCr & "_ Underscores are OK", _
   "What is the Bookmark Name?", Left(Trim _
   (Replace(myBookmarkRange.Text, " ", "_")), 45))

Use one .add line:
.Add Range:=myBookmarkRange, Name:=BookmarkName

Good Luck!

> Back again without success - it's more of a challenge than a need since the
> TOC way pretty well does what I want but there are times when I should like
[quoted text clipped - 58 lines]
>>>>>    .ShowHidden = False
>>>>> End With

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

Francis Hookham - 05 Jul 2007 11:49 GMT
Again Russ - apologies for not getting back on all your help - busy, busy -
I'm going to have to let this one keep for a bit longer - I'm limping with
my workhorse computer in for repair and a holiday coming up - might not get
to it until mid-Aug

Thanks VERY much

Francis

> Francis,
> Showing the code is a good idea, but you also neglected to say on which
[quoted text clipped - 107 lines]
>>>>>>    .ShowHidden = False
>>>>>> End With
 
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.